Rev 5: Refactor a bit. in http://bazaar.launchpad.net/~jameinel/my_nick

John Arbash Meinel john at arbash-meinel.com
Fri May 21 22:54:18 BST 2010


At http://bazaar.launchpad.net/~jameinel/my_nick

------------------------------------------------------------
revno: 5
revision-id: john at arbash-meinel.com-20100521215403-g75yokyeqd420n0e
parent: john at arbash-meinel.com-20100521214831-l6ak8dphymf3vgvy
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: my_nick
timestamp: Fri 2010-05-21 16:54:03 -0500
message:
  Refactor a bit.
-------------- next part --------------
=== modified file 'Makefile'
--- a/Makefile	2010-05-20 03:11:22 +0000
+++ b/Makefile	2010-05-21 21:54:03 +0000
@@ -4,6 +4,6 @@
 all: my_nick$(EXE)
 
 my_nick$(EXE): my_nick.cpp
-	g++ my_nick.cpp -o my_nick$(EXE) -mno-cygwin
+	g++ my_nick.cpp -Wall -o my_nick$(EXE) -mno-cygwin
 
 # vim: ts=4 sw=4 noet ft=make

=== modified file 'my_nick.cpp'
--- a/my_nick.cpp	2010-05-21 21:48:31 +0000
+++ b/my_nick.cpp	2010-05-21 21:54:03 +0000
@@ -180,6 +180,27 @@
     return string(buf);
 }
 
+string
+get_nick(string path)
+{
+    path = find_containing_bzrdir(path);
+    if (path.empty()) {
+        return string("");
+    }
+    if (!is_branch(path)) {
+        return string("");
+    }
+    string checkout_location = is_checkout_of(path);
+    string short_name;
+    if (checkout_location.empty()) {
+        // cerr << "path to short" << endl;
+        short_name = path_to_short(path);
+    } else {
+        short_name = checkout_to_short(checkout_location);
+    }
+    return short_name;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -192,24 +213,9 @@
         cout << "<invalid>" << endl;
         return 2;
     }
-    path = find_containing_bzrdir(path);
-    if (path.empty()) {
-        return 0;
-    }
-    if (!is_branch(path)) {
-        return 0;
-    }
-    string checkout_location = is_checkout_of(path);
-    string short_name;
-    if (checkout_location.empty()) {
-        // cerr << "path to short" << endl;
-        short_name = path_to_short(path);
-    } else {
-        short_name = checkout_to_short(checkout_location);
-    }
-    if (short_name.empty()) {
-        return 1;
-    }
-    cout << short_name << endl;
-    return 0;
+    string nick = get_nick(path);
+    if (!nick.empty()) {
+        cout << " {" << nick << "}";
+    }
+    cout << endl;
 }



More information about the bazaar-commits mailing list