Don't use patches/<branch>/current
PATCH 1/1 Don't use patches/<branch>/current
The name of the current patch, if any, is always the last line of patches/<branch>/applied (and there is no current patch if and only if the "applied" file is empty). So use that instead, and stop having to worry about keeping the redundant "current" file up-to-date.
---
This is another remove-redundant-metadata cleanup patch. Not only does it remove more code than it adds, the removed code (mostly calls to __set_current) is the kind that one easily forgets to insert in the proper places when writing new code.
stgit/stack.py | 35 +++++++++-------------------------- 1 files changed, 9 insertions(+), 26 deletions(-)
stgit/stack.py +9 -26
@@ -295,7 +295,6 @@ class Series(StgitObject): self.__applied_file = os.path.join(self._dir(), 'applied') self.__unapplied_file = os.path.join(self._dir(), 'unapplied') self.__hidden_file = os.path.join(self._dir(), 'hidden') - self.__current_file = os.path.join(self._dir(), 'current') self.__descr_file = os.path.join(self._dir(), 'description') # where this series keeps its patches
@@ -325,11 +324,6 @@ class Series(StgitObject): """ return self.__name - def __set_current(self, name): - """Sets the topmost patch - """ - self._set_field('current', name) - def get_patch(self, name): """Return a Patch object for the given name """
@@ -346,11 +340,16 @@ class Series(StgitObject): def get_current(self): """Return the name of the topmost patch, or None if there is no such patch.""" - name = self._get_field('current') - if name == '': + try: + applied = self.get_applied() + except StackException: + # No "applied" file: branch is not initialized. + return None + try: + return applied[-1] + except IndexError: + # No patches applied. return None - else: - return name def get_applied(self): if not os.path.isfile(self.__applied_file):
@@ -650,8 +649,6 @@ class Series(StgitObject): os.remove(self.__unapplied_file) if os.path.exists(self.__hidden_file): os.remove(self.__hidden_file) - if os.path.exists(self.__current_file): - os.remove(self.__current_file) if os.path.exists(self.__descr_file): os.remove(self.__descr_file) if os.path.exists(self._dir()+'/orig-base'):
@@ -825,11 +822,8 @@ class Series(StgitObject): self.log_patch(patch, 'new') insert_string(self.__applied_file, patch.get_name()) - if not self.get_current(): - self.__set_current(name) else: append_string(self.__applied_file, patch.get_name()) - self.__set_current(name) if refresh: self.refresh_patch(cache_update = False, log = 'new')
@@ -936,8 +930,6 @@ class Series(StgitObject): f.writelines([line + '\n' for line in unapplied]) f.close() - self.__set_current(name) - return forwarded def merged_patches(self, names):
@@ -1019,8 +1011,6 @@ class Series(StgitObject): f.writelines([line + '\n' for line in unapplied]) f.close() - self.__set_current(name) - # head == bottom case doesn't need to refresh the patch if empty or head != bottom: if not ex:
@@ -1098,11 +1088,6 @@ class Series(StgitObject): f.writelines([line + '\n' for line in applied]) f.close() - if applied == []: - self.__set_current(None) - else: - self.__set_current(applied[-1]) - def empty_patch(self, name): """Returns True if the patch is empty """
@@ -1144,8 +1129,6 @@ class Series(StgitObject): f.close() elif oldname in applied: Patch(oldname, self.__patch_dir, self.__refs_dir).rename(newname) - if oldname == self.get_current(): - self.__set_current(newname) applied[applied.index(oldname)] = newname
Quoted 4 lines · Karl Hasselström
The name of the current patch, if any, is always the last line of patches/<branch>/applied (and there is no current patch if and only if the "applied" file is empty). So use that instead, and stop having to worry about keeping the redundant "current" file up-to-date.
I applied this patch. Could you also send me a patch for the bash-completion script as it uses this file?
I think the self.__current_file (same for the base file removed in a different patch) should still be available in the Series object and removed when deleting a branch, otherwise you get a "Series directory ... is not empty" exception.
Thanks.
Signature · 1 line
Catalin
Quoted 9 lines · Catalin Marinas
Quoted 4 lines · Karl Hasselström
The name of the current patch, if any, is always the last line of patches/<branch>/applied (and there is no current patch if and only if the "applied" file is empty). So use that instead, and stop having to worry about keeping the redundant "current" file up-to-date.
I applied this patch. Could you also send me a patch for the bash-completion script as it uses this file?
Quoted 7 lines
I think the self.__current_file (same for the base file removed in a different patch) should still be available in the Series object and removed when deleting a branch, otherwise you get a "Series directory ... is not empty" exception.
Thanks.
Hi,
this is a bit OT,
but when i wanted to try out this changes i found that 2 unrelated patches in you repo[1] are empty.
* Store branch description in the config file
* Make the "name" argument to "stg new" optional
Is that a problem on my side, or are they really empty?
Greetings Peter
[1] http://homepage.ntlworld.com/cmarinas/stgit.git
which is mirrored at
http://repo.or.cz/w/stgit.git
Quoted 4 lines · Peter Oberndorfer
this is a bit OT,
but when i wanted to try out this changes i found that 2 unrelated patches in you repo[1] are empty.
* Store branch description in the config file
* Make the "name" argument to "stg new" optional
Thanks for pointing out. They failed to apply cleanly last night and forgot to delete the empty patches created. I fixed the conflicts and added them today (I'll push them tonight).
Signature · 1 line
Catalin
Quoted 10 lines · Catalin Marinas
Quoted 5 lines · Karl Hasselström
The name of the current patch, if any, is always the last line of patches/<branch>/applied (and there is no current patch if and only if the "applied" file is empty). So use that instead, and stop having to worry about keeping the redundant "current" file up-to-date.
I applied this patch. Could you also send me a patch for the bash-completion script as it uses this file?
I realized this myself yesterday or so, and patched it to not need the current, applied, and unapplied files. Are you OK with that patch, or would you like one that keeps using {,un}applied?
Quoted 4 lines
I think the self.__current_file (same for the base file removed in a different patch) should still be available in the Series object and removed when deleting a branch, otherwise you get a "Series directory ... is not empty" exception.
Ah, very true. I'll whip up a fix.
Same question there: are you OK with a single fix for base, current, applied, and unapplied, or do you want them separate?
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/1 Remove obsolete files when deleting a branch
---
stgit/stack.py | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
stgit/stack.py +10 -0
@@ -660,6 +660,16 @@ class Series(StgitObject): if os.path.exists(self._dir()+'/orig-base'): os.remove(self._dir()+'/orig-base') + # Remove obsolete files that StGIT no longer uses, but + # that might still be around if this is an old repository. + for obsolete in ([os.path.join(self._dir(), fn) + for fn in ['current', 'description', + 'applied', 'unapplied']] + + [os.path.join(self.__base_dir, + 'refs', 'bases', self.__name)]): + if os.path.exists(obsolete): + os.remove(obsolete) + if not os.listdir(self.__patch_dir): os.rmdir(self.__patch_dir) else:
Quoted 10 lines · Karl Hasselström
Quoted 8 lines · Catalin Marinas
Quoted 5 lines · Karl Hasselström
The name of the current patch, if any, is always the last line of patches/<branch>/applied (and there is no current patch if and only if the "applied" file is empty). So use that instead, and stop having to worry about keeping the redundant "current" file up-to-date.
Quoted 6 lines
Quoted 2 lines
I applied this patch. Could you also send me a patch for the bash-completion script as it uses this file?
I realized this myself yesterday or so, and patched it to not need the current, applied, and unapplied files. Are you OK with that patch, or would you like one that keeps using {,un}applied?
What is the impact on the bash completion for calling StGIT rather than reading those files? Is it visible? If I integrate the DAG patches, there probably isn't other way anyway.
Quoted 9 lines
Quoted 4 lines
I think the self.__current_file (same for the base file removed in a different patch) should still be available in the Series object and removed when deleting a branch, otherwise you get a "Series directory ... is not empty" exception.
Ah, very true. I'll whip up a fix.
Same question there: are you OK with a single fix for base, current, applied, and unapplied, or do you want them separate?
Whatever is easier for you :-), I don't have any preference.
I'll push the patches I integrated in the next hour or so and you can base your changes on them.
Thanks.
Signature · 1 line
Catalin
Quoted 2 lines · Catalin Marinas
What is the impact on the bash completion for calling StGIT rather than reading those files? Is it visible?
Yes, it's visible, but not annoying (to me anyway). The overhead is akin to the overhead we used to have when "stg help" generated the command names -- on the order of 100-200 ms, when StGIT is in the cache. The expensive part is to start stgit; the git calls are cheap. So theoretically the completion script could duplicate the logic in StGIT and avoid most of the overhead, if someone wanted it badly enough.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Quoted 5 lines · Karl Hasselström
Quoted 2 lines · Catalin Marinas
What is the impact on the bash completion for calling StGIT rather than reading those files? Is it visible?
Quoted 7 lines
Yes, it's visible, but not annoying (to me anyway). The overhead is akin to the overhead we used to have when "stg help" generated the command names -- on the order of 100-200 ms, when StGIT is in the cache. The expensive part is to start stgit; the git calls are cheap. So theoretically the completion script could duplicate the logic in StGIT and avoid most of the overhead, if someone wanted it badly enough.
I did a quick test of 'stg series' with the DAG patches applied, on a Linux kernel repository ('du -sh .git' is 285M) with 42 patches (only 25 applied). It constantly takes over 2 seconds to complete (compared to < 200ms without the DAG patches). The problem is that this delay will happen for bash completion as well.
It seems that most of the time is spent in git._output_lines() called from stack.read_refs() (for git-show-ref). I attach the profiling output generated by stg-prof.
Signature · 1 line
Catalin
+ cross-arm
+ init-err
+ ll-printk
+ compressed-head-stack
+ armv7-uncompress
+ armv7-tlb
+ armv7-xenon
+ armv7-vfpv3
+ armv7-neon
+ armv7-thumb2-user
+ pb926-pci-io
+ mpcore-smsc911x
+ smsc911x-driver
+ realview-eb-pci-mem
+ realview-eb-pci-io
+ nommu-consistent-api
+ nommu-fault
+ nommu-page-tlb
+ nommu-context-id
+ nommu-integrator
+ nommu-realview-eb
+ nommu-kconfig
+ nommu-ptrace
+ nommu-armv6
Quoted 1 line
nommu-armv7
- per-cpu-asids
- arch-dsb-mmiowb
- t2-arch-arm-clone
- t2-function-type
- t2-exception-handling
- t2-unified-syntax
- t2-exception-handling-alternative
- t2-srs-variant
- thumb2-kernel-port
- errata-arm1136-364296
- errata-arm1136-411920
- pipt-icache-flush
- smp-writealloc
3150 function calls (3112 primitive calls) in 2.229 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 2.229 2.229 <string>:1(?)
1 0.000 0.000 0.000 0.000 ConfigParser.py:105(Error)
1 0.000 0.000 0.000 0.000 ConfigParser.py:117(NoSectionError)
1 0.000 0.000 0.000 0.000 ConfigParser.py:124(DuplicateSectionError)
1 0.000 0.000 0.000 0.000 ConfigParser.py:131(NoOptionError)
1 0.000 0.000 0.000 0.000 ConfigParser.py:140(InterpolationError)
1 0.000 0.000 0.000 0.000 ConfigParser.py:148(InterpolationMissingOptionError)
1 0.000 0.000 0.000 0.000 ConfigParser.py:161(InterpolationSyntaxError)
1 0.000 0.000 0.000 0.000 ConfigParser.py:165(InterpolationDepthError)
1 0.000 0.000 0.000 0.000 ConfigParser.py:176(ParsingError)
1 0.000 0.000 0.000 0.000 ConfigParser.py:188(MissingSectionHeaderError)
1 0.000 0.000 0.009 0.009 ConfigParser.py:202(RawConfigParser)
1 0.000 0.000 0.000 0.000 ConfigParser.py:487(ConfigParser)
1 0.000 0.000 0.002 0.002 ConfigParser.py:570(SafeConfigParser)
1 0.000 0.000 0.011 0.011 ConfigParser.py:88(?)
1 0.000 0.000 0.000 0.000 UserDict.py:19(__getitem__)
1 0.000 0.000 0.000 0.000 UserDict.py:62(__contains__)
1 0.000 0.000 0.000 0.000 basedir.py:2(?)
1 0.007 0.007 0.007 0.007 basedir.py:23(__output)
1 0.000 0.000 0.007 0.007 basedir.py:33(get)
1 0.003 0.003 0.011 0.011 common.py:2(?)
1 0.000 0.000 0.000 0.000 common.py:32(CmdException)
1 0.000 0.000 0.000 0.000 common.py:37(RevParseException)
1 0.000 0.000 0.006 0.006 config.py:125(config_setup)
1 0.000 0.000 0.000 0.000 config.py:134(ConfigOption)
2 0.000 0.000 0.000 0.000 config.py:137(__init__)
1 0.000 0.000 0.000 0.000 config.py:2(?)
1 0.000 0.000 0.000 0.000 config.py:24(GitConfigException)
1 0.000 0.000 0.000 0.000 config.py:27(GitConfig)
1 0.006 0.006 0.006 0.006 config.py:65(get)
1 0.005 0.005 0.023 0.023 git.py:180(_output_one_line)
2 2.029 1.015 2.067 1.034 git.py:192(_output_lines)
1 0.002 0.002 0.003 0.003 git.py:2(?)
1 0.000 0.000 0.023 0.023 git.py:288(get_head_file)
1 0.000 0.000 0.000 0.000 git.py:30(GitException)
1 0.000 0.000 0.000 0.000 git.py:39(Person)
1 0.000 0.000 0.000 0.000 git.py:71(Commit)
1 0.000 0.000 0.000 0.000 gitmergeonefile.py:2(?)
1 0.000 0.000 0.000 0.000 gitmergeonefile.py:27(GitMergeException)
1 0.001 0.001 2.228 2.228 main.py:197(main)
1 0.000 0.000 0.000 0.000 main.py:32(canonical_cmd)
1 0.000 0.000 0.015 0.015 main.py:51(__getitem__)
1 0.000 0.000 0.000 0.000 optparse.py:1007(_create_option_list)
1 0.000 0.000 0.001 0.001 optparse.py:1012(_populate_option_list)
1 0.000 0.000 0.000 0.000 optparse.py:1022(_init_parsing_state)
1 0.000 0.000 0.000 0.000 optparse.py:1036(set_usage)
1 0.000 0.000 0.000 0.000 optparse.py:1059(get_default_values)
1 0.000 0.000 0.000 0.000 optparse.py:1091(_get_args)
1 0.000 0.000 0.000 0.000 optparse.py:1097(parse_args)
1 0.000 0.000 0.000 0.000 optparse.py:1136(check_values)
1 0.000 0.000 0.000 0.000 optparse.py:1149(_process_args)
1 0.000 0.000 0.000 0.000 optparse.py:140(__init__)
1 0.000 0.000 0.000 0.000 optparse.py:247(__init__)
12 0.001 0.000 0.002 0.000 optparse.py:413(__init__)
12 0.000 0.000 0.000 0.000 optparse.py:432(_check_opt_strings)
12 0.000 0.000 0.000 0.000 optparse.py:441(_set_opt_strings)
12 0.000 0.000 0.000 0.000 optparse.py:462(_set_attrs)
12 0.000 0.000 0.000 0.000 optparse.py:480(_check_action)
12 0.000 0.000 0.000 0.000 optparse.py:486(_check_type)
12 0.000 0.000 0.000 0.000 optparse.py:504(_check_choice)
12 0.000 0.000 0.000 0.000 optparse.py:517(_check_dest)
12 0.000 0.000 0.000 0.000 optparse.py:528(_check_const)
12 0.000 0.000 0.000 0.000 optparse.py:534(_check_nargs)
12 0.000 0.000 0.000 0.000 optparse.py:543(_check_callback)
1 0.000 0.000 0.000 0.000 optparse.py:662(__init__)
1 0.000 0.000 0.000 0.000 optparse.py:748(__init__)
1 0.000 0.000 0.000 0.000 optparse.py:759(_create_option_mappings)
1 0.000 0.000 0.000 0.000 optparse.py:775(set_conflict_handler)
1 0.000 0.000 0.000 0.000 optparse.py:780(set_description)
13 0.000 0.000 0.000 0.000 optparse.py:786(_check_conflict)
13 0.000 0.000 0.001 0.000 optparse.py:815(add_option)
1 0.000 0.000 0.001 0.001 optparse.py:845(add_options)
1 0.000 0.000 0.001 0.001 optparse.py:975(__init__)
1 0.000 0.000 0.000 0.000 os.py:444(__setitem__)
4 0.000 0.000 0.000 0.000 popen2.py:21(_cleanup)
1 0.000 0.000 0.000 0.000 popen2.py:25(Popen3)
4 0.064 0.016 0.064 0.016 popen2.py:31(__init__)
1 0.000 0.000 0.000 0.000 popen2.py:7(?)
3 0.000 0.000 0.000 0.000 popen2.py:87(wait)
1 0.000 0.000 0.000 0.000 popen2.py:97(Popen4)
1 0.000 0.000 0.000 0.000 posixpath.py:110(basename)
5 0.000 0.000 0.000 0.000 posixpath.py:184(isdir)
4 0.000 0.000 0.000 0.000 posixpath.py:197(isfile)
8 0.000 0.000 0.000 0.000 posixpath.py:56(join)
1 0.000 0.000 0.000 0.000 posixpath.py:74(split)
1 0.000 0.000 2.229 2.229 profile:0(main())
0 0.000 0.000 profile:0(profiler)
1 0.001 0.001 2.163 2.163 series.py:111(func)
1 0.001 0.001 0.015 0.015 series.py:2(?)
38 0.001 0.000 0.001 0.000 series.py:88(__print_patch)
46 0.000 0.000 0.000 0.000 sets.py:119(__iter__)
1 0.000 0.000 0.000 0.000 sets.py:356(_update)
1 0.000 0.000 0.000 0.000 sets.py:393(ImmutableSet)
1 0.001 0.001 0.001 0.001 sets.py:41(?)
1 0.000 0.000 0.000 0.000 sets.py:418(Set)
72 0.001 0.000 0.001 0.000 sets.py:425(__init__)
89 0.001 0.000 0.001 0.000 sets.py:515(add)
25 0.000 0.000 0.000 0.000 sets.py:528(remove)
1 0.000 0.000 0.000 0.000 sets.py:564(_TemporarilyImmutableSet)
1 0.000 0.000 0.000 0.000 sets.py:83(BaseSet)
26 0.000 0.000 0.000 0.000 sets.py:99(__len__)
1 0.000 0.000 0.000 0.000 shutil.py:16(Error)
1 0.000 0.000 0.000 0.000 shutil.py:5(?)
896 0.017 0.000 0.028 0.000 sre.py:129(match)
4 0.000 0.000 0.013 0.003 sre.py:177(compile)
900 0.012 0.000 0.025 0.000 sre.py:216(_compile)
5 0.000 0.000 0.001 0.000 sre_compile.py:151(_compile_charset)
5 0.000 0.000 0.000 0.000 sre_compile.py:180(_optimize_charset)
17/4 0.001 0.000 0.002 0.001 sre_compile.py:24(_compile)
7 0.000 0.000 0.000 0.000 sre_compile.py:324(_simple)
4 0.000 0.000 0.001 0.000 sre_compile.py:331(_compile_info)
12 0.000 0.000 0.000 0.000 sre_compile.py:42(<lambda>)
8 0.000 0.000 0.000 0.000 sre_compile.py:440(isstring)
4 0.000 0.000 0.004 0.001 sre_compile.py:446(_code)
4 0.000 0.000 0.013 0.003 sre_compile.py:461(compile)
32 0.000 0.000 0.000 0.000 sre_parse.py:133(__len__)
51 0.000 0.000 0.000 0.000 sre_parse.py:137(__getitem__)
7 0.000 0.000 0.000 0.000 sre_parse.py:139(__setitem__)
7 0.000 0.000 0.000 0.000 sre_parse.py:141(__getslice__)
44 0.000 0.000 0.000 0.000 sre_parse.py:145(append)
24/11 0.001 0.000 0.001 0.000 sre_parse.py:147(getwidth)
4 0.000 0.000 0.000 0.000 sre_parse.py:183(__init__)
125 0.001 0.000 0.001 0.000 sre_parse.py:187(__next)
59 0.001 0.000 0.001 0.000 sre_parse.py:200(match)
98 0.002 0.000 0.003 0.000 sre_parse.py:206(get)
23 0.000 0.000 0.000 0.000 sre_parse.py:215(isident)
4 0.000 0.000 0.001 0.000 sre_parse.py:221(isname)
2 0.000 0.000 0.000 0.000 sre_parse.py:240(_class_escape)
6 0.000 0.000 0.000 0.000 sre_parse.py:269(_escape)
10/4 0.000 0.000 0.008 0.002 sre_parse.py:312(_parse_sub)
10/4 0.003 0.000 0.008 0.002 sre_parse.py:367(_parse)
4 0.000 0.000 0.009 0.002 sre_parse.py:614(parse)
4 0.000 0.000 0.000 0.000 sre_parse.py:75(__init__)
6 0.000 0.000 0.000 0.000 sre_parse.py:80(opengroup)
6 0.000 0.000 0.000 0.000 sre_parse.py:91(closegroup)
17 0.000 0.000 0.000 0.000 sre_parse.py:98(__init__)
1 0.000 0.000 0.000 0.000 stack.py:112(StgitObject)
1 0.000 0.000 0.000 0.000 stack.py:115(_set_dir)
6 0.000 0.000 0.000 0.000 stack.py:117(_dir)
1 0.000 0.000 0.000 0.000 stack.py:142(Patch)
1 0.004 0.004 0.008 0.008 stack.py:2(?)
1 0.000 0.000 0.000 0.000 stack.py:277(PatchorderCache)
1 0.000 0.000 0.000 0.000 stack.py:280(__init__)
1 0.000 0.000 0.000 0.000 stack.py:283(__invalidate)
59 0.001 0.000 0.001 0.000 stack.py:286(__cache)
2 0.000 0.000 0.000 0.000 stack.py:293(read_file)
1 0.000 0.000 0.000 0.000 stack.py:30(StackException)
59 0.005 0.000 0.007 0.000 stack.py:315(cmp)
1 0.014 0.014 0.110 0.110 stack.py:327(read_refs)
1 0.000 0.000 0.000 0.000 stack.py:33(FilterUntil)
1 0.002 0.002 2.006 2.006 stack.py:342(unapplied_patches)
1 0.026 0.026 0.037 0.037 stack.py:358(sort_applied_patches)
1 0.000 0.000 0.000 0.000 stack.py:382(AppliedCache)
1 0.000 0.000 0.000 0.000 stack.py:385(__init__)
2 0.000 0.000 2.161 1.080 stack.py:389(get_applied)
1 0.000 0.000 0.000 0.000 stack.py:392(get_unapplied)
1 0.000 0.000 0.000 0.000 stack.py:417(__invalidate)
3 0.000 0.000 0.000 0.000 stack.py:420(__cached)
3 0.001 0.000 2.161 0.720 stack.py:422(__cache)
1 0.000 0.000 0.000 0.000 stack.py:434(Series)
1 0.000 0.000 0.031 0.031 stack.py:437(__init__)
1 0.000 0.000 0.000 0.000 stack.py:479(get_branch)
1 0.000 0.000 0.000 0.000 stack.py:497(get_current)
2 0.000 0.000 2.161 1.080 stack.py:507(get_applied)
1 0.000 0.000 0.000 0.000 stack.py:510(get_unapplied)
1 0.000 0.000 0.000 0.000 stack.py:513(get_hidden)
2 0.000 0.000 0.000 0.000 stack.py:646(is_initialised)
8 0.000 0.000 0.000 0.000 stat.py:29(S_IFMT)
5 0.000 0.000 0.000 0.000 stat.py:45(S_ISDIR)
3 0.000 0.000 0.000 0.000 stat.py:54(S_ISREG)
1 0.000 0.000 0.000 0.000 templates.py:2(?)
1 0.000 0.000 0.000 0.000 utils.py:107(strip_prefix)
1 0.000 0.000 0.000 0.000 utils.py:153(EditorException)
1 0.001 0.001 0.001 0.001 utils.py:2(?)Ordered by: standard name
Function called...
<string>:1(?) main.py:197(main)(1) 2.228
ConfigParser.py:105(Error) --
ConfigParser.py:117(NoSectionError) --
ConfigParser.py:124(DuplicateSectionError) --
ConfigParser.py:131(NoOptionError) --
ConfigParser.py:140(InterpolationError) --
ConfigParser.py:148(InterpolationMissingOptionError) --
ConfigParser.py:161(InterpolationSyntaxError) --
ConfigParser.py:165(InterpolationDepthError) --
ConfigParser.py:176(ParsingError) --
ConfigParser.py:188(MissingSectionHeaderError) --
ConfigParser.py:202(RawConfigParser) sre.py:177(compile)(2) 0.013
ConfigParser.py:487(ConfigParser) --
ConfigParser.py:570(SafeConfigParser) sre.py:177(compile)(1) 0.013
ConfigParser.py:88(?) ConfigParser.py:105(Error)(1) 0.000
ConfigParser.py:117(NoSectionError)(1) 0.000
ConfigParser.py:124(DuplicateSectionError)(1) 0.000
ConfigParser.py:131(NoOptionError)(1) 0.000
ConfigParser.py:140(InterpolationError)(1) 0.000
ConfigParser.py:148(InterpolationMissingOptionError)(1) 0.000
ConfigParser.py:161(InterpolationSyntaxError)(1) 0.000
ConfigParser.py:165(InterpolationDepthError)(1) 0.000
ConfigParser.py:176(ParsingError)(1) 0.000
ConfigParser.py:188(MissingSectionHeaderError)(1) 0.000
ConfigParser.py:202(RawConfigParser)(1) 0.009
ConfigParser.py:487(ConfigParser)(1) 0.000
ConfigParser.py:570(SafeConfigParser)(1) 0.002
UserDict.py:19(__getitem__) --
UserDict.py:62(__contains__) --
basedir.py:2(?) --
basedir.py:23(__output) --
basedir.py:33(get) UserDict.py:62(__contains__)(1) 0.000
basedir.py:23(__output)(1) 0.007
common.py:2(?) common.py:32(CmdException)(1) 0.000
common.py:37(RevParseException)(1) 0.000
stack.py:2(?)(1) 0.008
utils.py:2(?)(1) 0.001
common.py:32(CmdException) --
common.py:37(RevParseException) --
config.py:125(config_setup) config.py:65(get)(1) 0.006
os.py:444(__setitem__)(1) 0.000
config.py:134(ConfigOption) --
config.py:137(__init__) --
config.py:2(?) basedir.py:2(?)(1) 0.000
config.py:24(GitConfigException)(1) 0.000
config.py:27(GitConfig)(1) 0.000
config.py:134(ConfigOption)(1) 0.000
config.py:24(GitConfigException) --
config.py:27(GitConfig) --
config.py:65(get) --
git.py:180(_output_one_line) popen2.py:31(__init__)(1) 0.064
popen2.py:87(wait)(1) 0.000
git.py:192(_output_lines) popen2.py:31(__init__)(2) 0.064
popen2.py:87(wait)(2) 0.000
git.py:2(?) git.py:30(GitException)(1) 0.000
git.py:39(Person)(1) 0.000
git.py:71(Commit)(1) 0.000
gitmergeonefile.py:2(?)(1) 0.000
sets.py:41(?)(1) 0.001
shutil.py:5(?)(1) 0.000
git.py:288(get_head_file) git.py:180(_output_one_line)(1) 0.023
utils.py:107(strip_prefix)(1) 0.000
git.py:30(GitException) --
git.py:39(Person) --
git.py:71(Commit) --
gitmergeonefile.py:2(?) config.py:137(__init__)(2) 0.000
gitmergeonefile.py:27(GitMergeException)(1) 0.000
gitmergeonefile.py:27(GitMergeException) --
main.py:197(main) ConfigParser.py:88(?)(1) 0.011
UserDict.py:19(__getitem__)(1) 0.000
config.py:125(config_setup)(1) 0.006
main.py:32(canonical_cmd)(1) 0.000
main.py:51(__getitem__)(1) 0.015
optparse.py:975(__init__)(1) 0.001
optparse.py:1097(parse_args)(1) 0.000
posixpath.py:110(basename)(1) 0.000
series.py:111(func)(1) 2.163
stack.py:437(__init__)(1) 0.031
main.py:32(canonical_cmd) --
main.py:51(__getitem__) series.py:2(?)(1) 0.015
optparse.py:1007(_create_option_list) optparse.py:759(_create_option_mappings)(1) 0.000
optparse.py:1012(_populate_option_list) optparse.py:815(add_option)(1) 0.001
optparse.py:845(add_options)(1) 0.001
optparse.py:1022(_init_parsing_state) --
optparse.py:1036(set_usage) --
optparse.py:1059(get_default_values) optparse.py:662(__init__)(1) 0.000
optparse.py:1091(_get_args) --
optparse.py:1097(parse_args) optparse.py:1059(get_default_values)(1) 0.000
optparse.py:1091(_get_args)(1) 0.000
optparse.py:1136(check_values)(1) 0.000
optparse.py:1149(_process_args)(1) 0.000
optparse.py:1136(check_values) --
optparse.py:1149(_process_args) --
optparse.py:140(__init__) --
optparse.py:247(__init__) optparse.py:140(__init__)(1) 0.000
optparse.py:413(__init__) optparse.py:432(_check_opt_strings)(12) 0.000
optparse.py:441(_set_opt_strings)(12) 0.000
optparse.py:462(_set_attrs)(12) 0.000
optparse.py:480(_check_action)(12) 0.000
optparse.py:486(_check_type)(12) 0.000
optparse.py:504(_check_choice)(12) 0.000
optparse.py:517(_check_dest)(12) 0.000
optparse.py:528(_check_const)(12) 0.000
optparse.py:534(_check_nargs)(12) 0.000
optparse.py:543(_check_callback)(12) 0.000
optparse.py:432(_check_opt_strings) --
optparse.py:441(_set_opt_strings) --
optparse.py:462(_set_attrs) --
optparse.py:480(_check_action) --
optparse.py:486(_check_type) --
optparse.py:504(_check_choice) --
optparse.py:517(_check_dest) --
optparse.py:528(_check_const) --
optparse.py:534(_check_nargs) --
optparse.py:543(_check_callback) --
optparse.py:662(__init__) --
optparse.py:748(__init__) optparse.py:775(set_conflict_handler)(1) 0.000
optparse.py:780(set_description)(1) 0.000
optparse.py:1007(_create_option_list)(1) 0.000
optparse.py:759(_create_option_mappings) --
optparse.py:775(set_conflict_handler) --
optparse.py:780(set_description) --
optparse.py:786(_check_conflict) --
optparse.py:815(add_option) optparse.py:786(_check_conflict)(13) 0.000
optparse.py:845(add_options) optparse.py:815(add_option)(12) 0.001
optparse.py:975(__init__) optparse.py:247(__init__)(1) 0.000
optparse.py:748(__init__)(1) 0.000
optparse.py:1012(_populate_option_list)(1) 0.001
optparse.py:1022(_init_parsing_state)(1) 0.000
optparse.py:1036(set_usage)(1) 0.000
os.py:444(__setitem__) --
popen2.py:21(_cleanup) --
popen2.py:25(Popen3) --
popen2.py:31(__init__) popen2.py:21(_cleanup)(4) 0.000
popen2.py:7(?) popen2.py:25(Popen3)(1) 0.000
popen2.py:97(Popen4)(1) 0.000
popen2.py:87(wait) --
popen2.py:97(Popen4) --
posixpath.py:110(basename) posixpath.py:74(split)(1) 0.000
posixpath.py:184(isdir) stat.py:45(S_ISDIR)(5) 0.000
posixpath.py:197(isfile) stat.py:54(S_ISREG)(3) 0.000
posixpath.py:56(join) --
posixpath.py:74(split) --
profile:0(main()) <string>:1(?)(1) 2.229
profile:0(profiler) profile:0(main())(1) 2.229
series.py:111(func) series.py:88(__print_patch)(38) 0.001
stack.py:497(get_current)(1) 0.000
stack.py:507(get_applied)(1) 2.161
stack.py:510(get_unapplied)(1) 0.000
stack.py:513(get_hidden)(1) 0.000
series.py:2(?) common.py:2(?)(1) 0.011
optparse.py:413(__init__)(12) 0.002
series.py:88(__print_patch) --
sets.py:119(__iter__) --
sets.py:356(_update) --
sets.py:393(ImmutableSet) --
sets.py:41(?) sets.py:83(BaseSet)(1) 0.000
sets.py:393(ImmutableSet)(1) 0.000
sets.py:418(Set)(1) 0.000
sets.py:564(_TemporarilyImmutableSet)(1) 0.000
sets.py:418(Set) --
sets.py:425(__init__) sets.py:356(_update)(1) 0.000
sets.py:515(add) --
sets.py:528(remove) --
sets.py:564(_TemporarilyImmutableSet) --
sets.py:83(BaseSet) --
sets.py:99(__len__) --
shutil.py:16(Error) --
shutil.py:5(?) shutil.py:16(Error)(1) 0.000
sre.py:129(match) sre.py:216(_compile)(896) 0.025
sre.py:177(compile) sre.py:216(_compile)(4) 0.025
sre.py:216(_compile) sre_compile.py:440(isstring)(4) 0.000
sre_compile.py:461(compile)(4) 0.013
sre_compile.py:151(_compile_charset) sre_compile.py:42(<lambda>)(6) 0.000
sre_compile.py:180(_optimize_charset)(5) 0.000
sre_compile.py:180(_optimize_charset) sre_compile.py:42(<lambda>)(6) 0.000
sre_compile.py:24(_compile) sre_compile.py:24(_compile)(13) 0.002
sre_compile.py:151(_compile_charset)(5) 0.001
sre_compile.py:324(_simple)(7) 0.000
sre_parse.py:137(__getitem__)(27) 0.000
sre_compile.py:324(_simple) sre_parse.py:137(__getitem__)(7) 0.000
sre_parse.py:147(getwidth)(7) 0.001
sre_compile.py:331(_compile_info) sre_parse.py:133(__len__)(4) 0.000
sre_parse.py:137(__getitem__)(3) 0.000
sre_parse.py:147(getwidth)(4) 0.001
sre_compile.py:42(<lambda>) --
sre_compile.py:440(isstring) --
sre_compile.py:446(_code) sre_compile.py:24(_compile)(4) 0.002
sre_compile.py:331(_compile_info)(4) 0.001
sre_compile.py:461(compile) sre_compile.py:440(isstring)(4) 0.000
sre_compile.py:446(_code)(4) 0.004
sre_parse.py:614(parse)(4) 0.009
sre_parse.py:133(__len__) --
sre_parse.py:137(__getitem__) --
sre_parse.py:139(__setitem__) --
sre_parse.py:141(__getslice__) sre_parse.py:98(__init__)(7) 0.000
sre_parse.py:145(append) --
sre_parse.py:147(getwidth) sre_parse.py:147(getwidth)(13) 0.001
sre_parse.py:183(__init__) sre_parse.py:187(__next)(4) 0.001
sre_parse.py:187(__next) --
sre_parse.py:200(match) sre_parse.py:187(__next)(23) 0.001
sre_parse.py:206(get) sre_parse.py:187(__next)(98) 0.001
sre_parse.py:215(isident) --
sre_parse.py:221(isname) sre_parse.py:215(isident)(23) 0.000
sre_parse.py:240(_class_escape) --
sre_parse.py:269(_escape) --
sre_parse.py:312(_parse_sub) sre_parse.py:200(match)(16) 0.001
sre_parse.py:367(_parse)(10) 0.008
sre_parse.py:367(_parse) sre_parse.py:80(opengroup)(6) 0.000
sre_parse.py:91(closegroup)(6) 0.000
sre_parse.py:98(__init__)(10) 0.000
sre_parse.py:133(__len__)(28) 0.000
sre_parse.py:137(__getitem__)(14) 0.000
sre_parse.py:139(__setitem__)(7) 0.000
sre_parse.py:141(__getslice__)(7) 0.000
sre_parse.py:145(append)(44) 0.000
sre_parse.py:200(match)(43) 0.001
sre_parse.py:206(get)(94) 0.003
sre_parse.py:221(isname)(4) 0.001
sre_parse.py:240(_class_escape)(2) 0.000
sre_parse.py:269(_escape)(6) 0.000
sre_parse.py:312(_parse_sub)(6) 0.008
sre_parse.py:614(parse) sre_parse.py:75(__init__)(4) 0.000
sre_parse.py:183(__init__)(4) 0.000
sre_parse.py:206(get)(4) 0.003
sre_parse.py:312(_parse_sub)(4) 0.008
sre_parse.py:75(__init__) --
sre_parse.py:80(opengroup) --
sre_parse.py:91(closegroup) --
sre_parse.py:98(__init__) --
stack.py:112(StgitObject) --
stack.py:115(_set_dir) --
stack.py:117(_dir) --
stack.py:142(Patch) --
stack.py:2(?) git.py:2(?)(1) 0.003
popen2.py:7(?)(1) 0.000
stack.py:30(StackException)(1) 0.000
stack.py:33(FilterUntil)(1) 0.000
stack.py:112(StgitObject)(1) 0.000
stack.py:142(Patch)(1) 0.000
stack.py:277(PatchorderCache)(1) 0.000
stack.py:382(AppliedCache)(1) 0.000
stack.py:434(Series)(1) 0.000
templates.py:2(?)(1) 0.000
stack.py:277(PatchorderCache) --
stack.py:280(__init__) stack.py:283(__invalidate)(1) 0.000
stack.py:283(__invalidate) --
stack.py:286(__cache) posixpath.py:56(join)(3) 0.000
posixpath.py:197(isfile)(3) 0.000
stack.py:117(_dir)(3) 0.000
stack.py:293(read_file)(2) 0.000
stack.py:293(read_file) --
stack.py:30(StackException) --
stack.py:315(cmp) stack.py:286(__cache)(59) 0.001
stack.py:327(read_refs) git.py:192(_output_lines)(1) 2.067
sre.py:129(match)(896) 0.028
sre.py:177(compile)(1) 0.013
stack.py:33(FilterUntil) --
stack.py:342(unapplied_patches) git.py:192(_output_lines)(1) 2.067
sets.py:119(__iter__)(19) 0.000
sets.py:425(__init__)(46) 0.001
sets.py:515(add)(64) 0.001
stack.py:358(sort_applied_patches) popen2.py:31(__init__)(1) 0.064
sets.py:99(__len__)(26) 0.000
sets.py:119(__iter__)(25) 0.000
sets.py:425(__init__)(26) 0.001
sets.py:515(add)(25) 0.001
sets.py:528(remove)(25) 0.000
stack.py:382(AppliedCache) --
stack.py:385(__init__) stack.py:280(__init__)(1) 0.000
stack.py:417(__invalidate)(1) 0.000
stack.py:389(get_applied) stack.py:422(__cache)(2) 2.161
stack.py:392(get_unapplied) stack.py:422(__cache)(1) 2.161
stack.py:417(__invalidate) --
stack.py:420(__cached) --
stack.py:422(__cache) sets.py:119(__iter__)(2) 0.000
stack.py:315(cmp)(59) 0.007
stack.py:327(read_refs)(1) 0.110
stack.py:342(unapplied_patches)(1) 2.006
stack.py:358(sort_applied_patches)(1) 0.037
stack.py:420(__cached)(3) 0.000
stack.py:479(get_branch)(1) 0.000
stack.py:434(Series) --
stack.py:437(__init__) basedir.py:33(get)(1) 0.007
git.py:288(get_head_file)(1) 0.023
posixpath.py:56(join)(5) 0.000
posixpath.py:184(isdir)(3) 0.000
stack.py:115(_set_dir)(1) 0.000
stack.py:117(_dir)(3) 0.000
stack.py:385(__init__)(1) 0.000
stack.py:646(is_initialised)(2) 0.000
stack.py:479(get_branch) --
stack.py:497(get_current) stack.py:507(get_applied)(1) 2.161
stack.py:507(get_applied) stack.py:389(get_applied)(2) 2.161
stack.py:510(get_unapplied) stack.py:392(get_unapplied)(1) 0.000
stack.py:513(get_hidden) posixpath.py:197(isfile)(1) 0.000
stack.py:646(is_initialised) posixpath.py:184(isdir)(2) 0.000
stat.py:29(S_IFMT) --
stat.py:45(S_ISDIR) stat.py:29(S_IFMT)(5) 0.000
stat.py:54(S_ISREG) stat.py:29(S_IFMT)(3) 0.000
templates.py:2(?) --
utils.py:107(strip_prefix) --
utils.py:153(EditorException) --
utils.py:2(?) config.py:2(?)(1) 0.000
utils.py:153(EditorException)(1) 0.000Quoted 5 lines · Catalin Marinas
I did a quick test of 'stg series' with the DAG patches applied, on a Linux kernel repository ('du -sh .git' is 285M) with 42 patches (only 25 applied). It constantly takes over 2 seconds to complete (compared to < 200ms without the DAG patches). The problem is that this delay will happen for bash completion as well.
This is more than ten times as expensive as in my measurement. Curious. And the algorithm is designed so that it shouldn't take time proportional to the repository size, just proportional to the number of patches.
There are three git calls involved:
* List the references. There can't be more than a few hundred of them.
* rev-list all patches, subtracting everything that's reachable from the branch head. This set of commits should not be much larger than the number of unapplied patches.
* rev-list the branch head, but stop walking as soon as all applied patches have been seen. This set of commits should not be much larger than the number of applied patches.
None of the calls should be expensive.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Quoted 9 lines · Karl Hasselström
Quoted 6 lines · Catalin Marinas
I did a quick test of 'stg series' with the DAG patches applied, on a Linux kernel repository ('du -sh .git' is 285M) with 42 patches (only 25 applied). It constantly takes over 2 seconds to complete (compared to < 200ms without the DAG patches). The problem is that this delay will happen for bash completion as well.
Quoted 4 lines
This is more than ten times as expensive as in my measurement. Curious. And the algorithm is designed so that it shouldn't take time proportional to the repository size, just proportional to the number of patches.
I set up a kernel repository with 100 applied and 100 unapplied patches:
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git $ cd linux-2.6/ $ stg init $ for ((i=0;i<200;i++)); do stg new p$(printf '%03d' $i) -m "Patch $i"; done $ stg goto p099
Then repeatedly:
$ time stg series >/dev/null
This gives times such as
real 0m0.247s user 0m0.156s sys 0m0.060s
real 0m0.147s user 0m0.088s sys 0m0.036s
real 0m0.153s user 0m0.088s sys 0m0.032s
real 0m0.144s user 0m0.104s sys 0m0.024s
Tab completion also feels like it takes 0.1-0.2 seconds -- which it should, since it's implemented with series, applied, and unapplied, allow which do the same amount of work.
But my kernel repository is _much_ smaller than yours:
$ du -sh .git 183M .git
Do you perchance have a bunch of loose objects in there?
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Quoted 2 lines · Karl Hasselström
I set up a kernel repository with 100 applied and 100 unapplied patches:
[...]
Quoted 3 lines
Then repeatedly:
$ time stg series >/dev/null
I ran 'git repack -a -d' and 'git prune'. There are no other objects apart from the generated pack:
$ du -sh .git 211M .git
And then repeatedly 'time stg series > /dev/null':
real 0m1.638s user 0m1.422s sys 0m0.088s
real 0m2.542s user 0m1.436s sys 0m0.078s
real 0m2.916s user 0m1.424s sys 0m0.083s
real 0m2.940s user 0m1.425s sys 0m0.081s
real 0m1.614s user 0m1.421s sys 0m0.081s
real 0m1.587s user 0m1.423s sys 0m0.081s
real 0m2.653s user 0m1.427s sys 0m0.075s
Quoted 6 lines
But my kernel repository is _much_ smaller than yours:
$ du -sh .git 183M .gitDo you perchance have a bunch of loose objects in there?
It got smaller after repacking but it is still bigger than yours. Maybe the reason is that I have 14 branches with various patches, some of them just for historical reasons but going back to 2.6.12. There are also several commits generated for the patch logs.
The CPU is a P4 at 2.5GHz and the 'stg series' operation seems to be CPU bound rather than IO. I'm also using Python 2.3 on this PC and for this reason I changed 2 generator constructs (x for x in ...) with list comprehension (see the attached patch).
Signature · 1 line
Catalin
commit f7cc1f7fa6b2ee4f42e812970760ba5db5d2cafc
Author: Catalin Marinas <[email protected]> Date: Wed May 16 13:08:45 2007 +0100
refresh b5003aa7bb5ec384e1dbe2887c07885a791384c2
stgit/stack.py +3 -3
@@ -349,8 +349,8 @@ def unapplied_patches(ref2hash): unapplied = Set() for line in git._output_lines( 'git-rev-list --stdin', - ('%s%s\n' % (['', '^'][ref == None], sha1) - for ref, sha1 in ref2hash.iteritems())): + ['%s%s\n' % (['', '^'][ref == None], sha1) + for ref, sha1 in ref2hash.iteritems()]): for ref in hash2refs.get(line.strip(), []): unapplied.add(ref) return unapplied
@@ -364,7 +364,7 @@ def sort_applied_patches(ref2hash): if r != None: hash2refs.setdefault(h, Set()).add(r) - missing = Set(ref for ref in ref2hash.iterkeys() if ref != None) + missing = Set([ref for ref in ref2hash.iterkeys() if ref != None]) if not missing: return [] applied = []
Quoted 7 lines · Catalin Marinas
I ran 'git repack -a -d' and 'git prune'. There are no other objects apart from the generated pack:
$ du -sh .git 211M .gitAnd then repeatedly 'time stg series >
/dev/null':
Hmm, it seems there is a problem then. :-(
Quoted 4 lines
It got smaller after repacking but it is still bigger than yours. Maybe the reason is that I have 14 branches with various patches, some of them just for historical reasons but going back to 2.6.12. There are also several commits generated for the patch logs.
OK. That shouldn't matter, though, since that extra history shouldn't be examined anyway.
Quoted 4 lines
The CPU is a P4 at 2.5GHz and the 'stg series' operation seems to be CPU bound rather than IO. I'm also using Python 2.3 on this PC and for this reason I changed 2 generator constructs (x for x in ...) with list comprehension (see the attached patch).
I don't think that's the problem, since those lists are both small.
The only possibility I can think of that might explain this is that some of your unapplied patches are attached to a place in the commit DAG that's far away from the branch head (e.g. you have rebased to some entirely different place since you last had them applied), so that "git-rev-list patch ^branch" outputs a large part of the commit DAG.
Could you put counters in unapplied_patches() and sort_applied_patches() to see how many lines each of them reads from git-rev-list? The expected number (if it had taken just a little time, like it did for me) is a small constant times the number of patches in both cases.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Quoted 6 lines · Karl Hasselström
The only possibility I can think of that might explain this is that some of your unapplied patches are attached to a place in the commit DAG that's far away from the branch head (e.g. you have rebased to some entirely different place since you last had them applied), so that "git-rev-list patch ^branch" outputs a large part of the commit DAG.
That's probably the case. I have patches that I haven't rebased for months but I keep them in case they might be needed in the future. That's the reason for the hide/unhide commands. Anyway, I'm not yet prepared to give up my current workflow.
I haven't tried to understand your patch yet but the unapplied patches will never be in a linear DAG similar to the applied patches. Because of this, we need to keep their order in a file anyway and we might not need to run git-rev-list (BTW, how do you preserve the unapplied patches order with the DAG implementation?).
Quoted 5 lines
Could you put counters in
unapplied_patches()andsort_applied_patches()to see how many lines each of them reads from git-rev-list? The expected number (if it had taken just a little time, like it did for me) is a small constant times the number of patches in both cases.
I'll do this tomorrow to confirm but that's probably the cause of the slow-down.
Signature · 1 line
Catalin
Quoted 11 lines · Catalin Marinas
Quoted 6 lines · Karl Hasselström
The only possibility I can think of that might explain this is that some of your unapplied patches are attached to a place in the commit DAG that's far away from the branch head (e.g. you have rebased to some entirely different place since you last had them applied), so that "git-rev-list patch ^branch" outputs a large part of the commit DAG.
That's probably the case. I have patches that I haven't rebased for months but I keep them in case they might be needed in the future.
That's probably it, then. I'll need to come up with a clever scheme to make that case cheap again.
Quoted 1 line
That's the reason for the hide/unhide commands.
Ah.
Quoted 1 line
Anyway, I'm not yet prepared to give up my current workflow.
I didn't intend to make that workflow painful, so don't despair yet -- there might be a way to make it work.
Quoted 3 lines
I haven't tried to understand your patch yet but the unapplied patches will never be in a linear DAG similar to the applied patches.
I know.
Quoted 3 lines
Because of this, we need to keep their order in a file anyway and we might not need to run git-rev-list (BTW, how do you preserve the unapplied patches order with the DAG implementation?).
The order of _all_ patches is kept in the "patchorder" file. This file is consulted only when the relative order of two unapplied patches need to be established. (Applied patches are sorted by the DAG, and applied patches always precede unapplied patches.)
I would like to avoid keeping a record of known-to-be-unapplied patches; while this is nowhere near as important as not keeping a record of applied patches, it would still provide an opening for the user to confuse StGIT.
But I believe I have a cunning plan ...
Quoted 8 lines
Quoted 5 lines
Could you put counters in
unapplied_patches()andsort_applied_patches()to see how many lines each of them reads from git-rev-list? The expected number (if it had taken just a little time, like it did for me) is a small constant times the number of patches in both cases.I'll do this tomorrow to confirm but that's probably the cause of the slow-down.
Thanks for hanging in there.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
cover New and improved DAG appliedness series
This took a while, but here it is. (Actually, I finished this about a week ago, but had no Internet connection so I couldn't send it.)
The series starts with basically the same DAG appliedness test as before, with the same known performance bug. Later on in the series, the mechanism is changed to one that doesn't have the bug. I kept the intermediate, slow state because the changesets read better that way, and because the new mechanism is more complicated than the old so it might be useful to be able to compare their output in case some bug turns up further down the road.
To test the performance, I used a script (which I've unfortunately misplaced) that (in the kernel repository) reset to one point 10000 commits in the past and one 5000 commits in the past, pushed a few patches at each spot, and then created 100 applied and 100 unapplied patches on top of upstream HEAD. This triggers the performance bug with the first algorithm since we have unapplied commits very far from HEAD.
Both algorithms are documented in the patches that introduce them.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/6 Verify patch status during the test
---
t/t1200-push-modified.sh | 55 +++++++++++++++++++++++++++------------------- 1 files changed, 32 insertions(+), 23 deletions(-)
t/t1200-push-modified.sh +32 -23
@@ -19,23 +19,26 @@ specify --merged, then rollback and retry with the correct flag.' test_create_repo foo test_expect_success \ - 'Clone tree and setup changes' \ - "stg clone foo bar && - (cd bar && stg new p1 -m p1 - printf 'a\nc\n' > file && stg add file && stg refresh && - stg new p2 -m p2 - printf 'a\nb\nc\n' > file && stg refresh - ) -" + 'Clone tree and setup changes' ' + stg clone foo bar && + ( + cd bar && stg new p1 -m p1 + printf "a\nc\n" > file && stg add file && stg refresh && + stg new p2 -m p2 && + printf "a\nb\nc\n" > file && stg refresh && + [ "$(echo $(stg applied))" = "p1 p2" ] && + [ "$(echo $(stg unapplied))" = "" ] + ) +' test_expect_success \ - 'Port those patches to orig tree' \ - '(cd foo && - GIT_DIR=../bar/.git git-format-patch --stdout \ - $(cd ../bar && stg id base@master)..HEAD | - git-am -3 -k - ) - ' + 'Port those patches to orig tree' ' + ( + cd foo && + GIT_DIR=../bar/.git git-format-patch --stdout \ + $(cd ../bar && stg id base@master)..HEAD | git-am -3 -k + ) +' test_expect_success \ 'Pull to sync with parent, preparing for the problem' \
@@ -51,15 +54,21 @@ test_expect_failure \ " test_expect_success \ - 'Rollback the push' \ - "(cd bar && stg push --undo - ) -" + 'Rollback the push' ' + ( + cd bar && stg push --undo && + [ "$(echo $(stg applied))" = "" ] && + [ "$(echo $(stg unapplied))" = "p1 p2" ] + ) +' test_expect_success \ - 'Push those patches while checking they were merged upstream' \ - "(cd bar && stg push --merged --all - ) -" + 'Push those patches while checking they were merged upstream' ' + ( + cd bar && stg push --merged --all + [ "$(echo $(stg applied))" = "p1 p2" ] && + [ "$(echo $(stg unapplied))" = "" ] + ) +' test_done
PATCH 2/6 Make use of the get_patch() utility function
In reply to Karl HasselströmWe already had it, but no one was using it
---
stgit/stack.py | 27 +++++++++++++-------------- 1 files changed, 13 insertions(+), 14 deletions(-)
stgit/stack.py +13 -14
@@ -404,7 +404,7 @@ class Series(StgitObject): crt = self.get_current() if not crt: return None - return Patch(crt, self.__patch_dir, self.__refs_dir) + return self.get_patch(crt) def get_current(self): """Return the name of the topmost patch, or None if there is
@@ -678,7 +678,7 @@ class Series(StgitObject): raise StackException, \ 'Cannot delete: the series still contains patches' for p in patches: - Patch(p, self.__patch_dir, self.__refs_dir).delete() + self.get_patch(p).delete() # remove the trash directory for fname in os.listdir(self.__trash_dir):
@@ -732,7 +732,7 @@ class Series(StgitObject): if not name: raise StackException, 'No patches applied' - patch = Patch(name, self.__patch_dir, self.__refs_dir) + patch = self.get_patch(name) descr = patch.get_description() if not (message or descr):
@@ -798,7 +798,7 @@ class Series(StgitObject): name = self.get_current() assert(name) - patch = Patch(name, self.__patch_dir, self.__refs_dir) + patch = self.get_patch(name) old_bottom = patch.get_old_bottom() old_top = patch.get_old_top()
@@ -839,7 +839,7 @@ class Series(StgitObject): if name == None: name = make_patch_name(descr, self.patch_exists) - patch = Patch(name, self.__patch_dir, self.__refs_dir) + patch = self.get_patch(name) patch.create() if bottom:
@@ -919,7 +919,7 @@ class Series(StgitObject): for name in names: assert(name in unapplied) - patch = Patch(name, self.__patch_dir, self.__refs_dir) + patch = self.get_patch(name) head = top bottom = patch.get_bottom()
@@ -988,8 +988,7 @@ class Series(StgitObject): patches detected to have been applied. The state of the tree is restored to the original one """ - patches = [Patch(name, self.__patch_dir, self.__refs_dir) - for name in names] + patches = [self.get_patch(name) for name in names] patches.reverse() merged = []
@@ -1008,7 +1007,7 @@ class Series(StgitObject): unapplied = self.get_unapplied() assert(name in unapplied) - patch = Patch(name, self.__patch_dir, self.__refs_dir) + patch = self.get_patch(name) head = git.get_head() bottom = patch.get_bottom()
@@ -1084,7 +1083,7 @@ class Series(StgitObject): name = self.get_current() assert(name) - patch = Patch(name, self.__patch_dir, self.__refs_dir) + patch = self.get_patch(name) old_bottom = patch.get_old_bottom() old_top = patch.get_old_top()
@@ -1110,7 +1109,7 @@ class Series(StgitObject): applied.reverse() assert(name in applied) - patch = Patch(name, self.__patch_dir, self.__refs_dir) + patch = self.get_patch(name) if git.get_head_file() == self.get_branch(): if keep and not git.apply_diff(git.get_head(), patch.get_bottom()):
@@ -1142,7 +1141,7 @@ class Series(StgitObject): """Returns True if the patch is empty """ self.__patch_name_valid(name) - patch = Patch(name, self.__patch_dir, self.__refs_dir) + patch = self.get_patch(name) bottom = patch.get_bottom() top = patch.get_top()
@@ -1171,14 +1170,14 @@ class Series(StgitObject): self.hide_patch(newname) if oldname in unapplied: - Patch(oldname, self.__patch_dir, self.__refs_dir).rename(newname) + self.get_patch(oldname).rename(newname) unapplied[unapplied.index(oldname)] = newname f = file(self.__unapplied_file, 'w+') f.writelines([line + '\n' for line in unapplied]) f.close() elif oldname in applied: - Patch(oldname, self.__patch_dir, self.__refs_dir).rename(newname) + self.get_patch(oldname).rename(newname) applied[applied.index(oldname)] = newname
PATCH 3/6 Compute patch appliedness from commit DAG
In reply to Karl HasselströmDon't rely on cached metadata in the "applied" and "unapplied" files to tell which patches are applied. Instead, consider the patches reachable from the branch head to be applied, and the rest unapplied.
The order of the applied patches is also taken from the DAG, but we can't do that for the unapplied patches. So the patch order is saved to a file whenever it changes, and that file is consulted whenever we need to compute the order of the unapplied patches.
The point of this excercise is to let users do things such as "git reset" without confusing stgit. This gives incrased flexibility to power users, and increased safety to other users. The advantages come from the removal of redundant metadata: it is no longer possible for StGIT's appliedness status to get out of sync with the underlying git commit DAG.
This is how the appliedness and order is computed:
* First, a single call to git-show-ref gives the hashes of all patches and the branch head.
* Then, "git-rev-list patch1 patch2 patch3 ^branch" lists a small set of hashes that contains all the unapplied patches and none of the applied patches.
* Last, "git-rev-list head" lists all commits in the branch. The applied patches are listed in the correct order.
This is efficient because none of the two rev-list calls need to look at more than a small part of the DAG. The first call returns a small set of commits, and the last call is abandoned before it has time to look far back in the DAG.
---
stgit/commands/commit.py | 8 - stgit/commands/float.py | 2 stgit/commands/imprt.py | 2 stgit/commands/refresh.py | 2 stgit/commands/sync.py | 2 stgit/git.py | 5 + stgit/stack.py | 333 +++++++++++++++++++++++++++++---------------- t/t4000-upgrade.sh | 6 + 8 files changed, 227 insertions(+), 133 deletions(-)
stgit/commands/commit.py +1 -7
@@ -52,14 +52,8 @@ def func(parser, options, args): if crt_series.get_protected(): raise CmdException, 'This branch is protected. Commit is not permitted' - crt_head = git.get_head() - out.start('Committing %d patches' % len(applied)) - - crt_series.pop_patch(applied[0]) - git.switch(crt_head) - for patch in applied: - crt_series.delete_patch(patch) + crt_series.delete_patch_data(patch) out.done()
stgit/commands/float.py +1 -1
@@ -48,7 +48,7 @@ def func(parser, options, args): check_head_top_equal() unapplied = crt_series.get_unapplied() - applied = crt_series.get_applied() + applied = list(crt_series.get_applied()) # a copy, since we'll modify it all = unapplied + applied if options.series:
stgit/commands/imprt.py +1 -1
@@ -294,7 +294,7 @@ def __create_patch(filename, message, author_name, author_email, git.apply_patch(diff = diff, base = git_id(options.base)) else: git.apply_patch(diff = diff) - crt_series.refresh_patch(edit = options.edit, + crt_series.refresh_patch(patch, edit = options.edit, show_patch = options.showpatch) out.done()
stgit/commands/refresh.py +1 -1
@@ -131,7 +131,7 @@ def func(parser, options, args): if autoresolved == 'yes': resolved_all() - crt_series.refresh_patch(files = args, + crt_series.refresh_patch(patch, files = args, message = options.message, edit = options.edit, show_patch = options.showpatch,
stgit/commands/sync.py +1 -1
@@ -161,7 +161,7 @@ def func(parser, options, args): if git.local_changes(verbose = False): # index (cache) already updated by the git merge. The # backup information was already reset above - crt_series.refresh_patch(cache_update = False, backup = False, + crt_series.refresh_patch(p, cache_update = False, backup = False, log = 'sync') out.done('updated') else:
stgit/git.py +4 -1
@@ -189,8 +189,11 @@ def _output_one_line(cmd, file_desc = None): p.childerr.read().strip()) return output -def _output_lines(cmd): +def _output_lines(cmd, input = []): p=popen2.Popen3(cmd, True) + for line in input: + p.tochild.write(line) + p.tochild.close() lines = p.fromchild.readlines() if p.wait(): raise GitException, '%s failed (%s)' % (str(cmd),
stgit/stack.py +212 -121
502 lines not on this page · raw message
t/t4000-upgrade.sh +6 -0
@@ -34,6 +34,12 @@ for ver in 0.12 0.8; do ! git show-ref --verify --quiet refs/bases/master ' + test_expect_success \ + "v$ver: Make sure the applied and unapplied files are gone" ' + [ ! -e .git/patches/master/applied ] && + [ ! -e .git/patches/master/unapplied ] +' + cd .. done
PATCH 4/6 Test the new DAG appliedness machinery
In reply to Karl Hasselström---
t/t3000-git-interop.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 60 insertions(+), 0 deletions(-)
t/t3000-git-interop.sh new file +60 -0
@@ -0,0 +1,60 @@ +#!/bin/sh +# Copyright (c) 2007 Karl Hasselström +test_description='Test git/StGIT interoperability' +. ./test-lib.sh + +test_expect_success \ + 'Create some git-only history' ' + echo foo > foo.txt && + git add foo.txt && + git commit -a -m foo && + git tag foo-tag && + for i in 0 1 2 3 4; do + echo foo$i >> foo.txt && + git commit -a -m foo$i; + done +' + +test_expect_success \ + 'Initialize the StGIT repository' ' + stg init +' + +test_expect_success \ + 'Create five patches' ' + for i in 0 1 2 3 4; do + stg new p$i -m p$i; + done && + [ "$(echo $(stg applied))" = "p0 p1 p2 p3 p4" ] && + [ "$(echo $(stg unapplied))" = "" ] +' + +test_expect_success \ + 'Pop two patches with git-reset' ' + git reset --hard HEAD~2 && + [ "$(echo $(stg applied))" = "p0 p1 p2" ] && + [ "$(echo $(stg unapplied))" = "p3 p4" ] +' + +test_expect_success \ + 'Create a new patch' ' + stg new q0 -m q0 && + [ "$(echo $(stg applied))" = "p0 p1 p2 q0" ] && + [ "$(echo $(stg unapplied))" = "p3 p4" ] +' + +test_expect_success \ + 'Go to an unapplied patch with with git-reset' ' + git reset --hard $(stg id p3) && + [ "$(echo $(stg applied))" = "p0 p1 p2 p3" ] && + [ "$(echo $(stg unapplied))" = "q0 p4" ] +' + +test_expect_success \ + 'Go back to below the stack base with git-reset' ' + git reset --hard foo-tag && + [ "$(echo $(stg applied))" = "" ] && + [ "$(echo $(stg unapplied))" = "p0 p1 p2 q0 p3 p4" ] +' + +test_done
PATCH 5/6 Fix bash completion after the DAG appliedness patch
In reply to Karl HasselströmThe bash tab completion used the "applied", "unapplied" and "current" files to generate completions. Since these don't exist anymore, use stg applied/unapplied/series to obtain the same info. It's a bit slower, but not terribly much so.
---
contrib/stgit-completion.bash | 15 ++++----------- 1 files changed, 4 insertions(+), 11 deletions(-)
contrib/stgit-completion.bash +4 -11
@@ -70,32 +70,25 @@ _current_branch () # List of all applied patches. _applied_patches () { - local g=$(_gitdir) - [ "$g" ] && cat "$g/patches/$(_current_branch)/applied" + stg applied 2> /dev/null } # List of all unapplied patches. _unapplied_patches () { - local g=$(_gitdir) - [ "$g" ] && cat "$g/patches/$(_current_branch)/unapplied" + stg unapplied 2> /dev/null } # List of all patches. _all_patches () { - local b=$(_current_branch) - local g=$(_gitdir) - [ "$g" ] && cat "$g/patches/$b/applied" "$g/patches/$b/unapplied" + stg series --noprefix 2> /dev/null } # List of all patches except the current patch. _all_other_patches () { - local b=$(_current_branch) - local g=$(_gitdir) - [ "$g" ] && cat "$g/patches/$b/applied" "$g/patches/$b/unapplied" \ - | grep -v "^$(cat $g/patches/$b/current 2> /dev/null)$" + stg series 2> /dev/null | grep -v '^>' | cut -f 2 -d ' ' } _all_branches ()
PATCH 6/6 Speed up the appliedness test
In reply to Karl HasselströmThe appliedness test was too slow if at least one patch, applied or unapplied, was too far away from HEAD, since we had to visit the whole intervening part of the commit DAG.
This patch fixes that problem by maintaining a cache of uninteresting commits that are known to not reach any patches in the commit DAG. (Specifically, this is at all times the set of commits that are parents to patch commits and do not have a patch commit as their ancestor.) By exlcuding these commits when walking the graph, we only have to visit the interesting places.
As a nice side effect, the cache of uninteresting commits makes it possible to use just one git-rev-list call instead of two, since we can list the applied patches without first computing the unapplied patches; the unapplied patches are then simply all patches except those that are applied.
---
stgit/stack.py | 278 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 223 insertions(+), 55 deletions(-)
stgit/stack.py +223 -55
@@ -156,7 +156,7 @@ class Patch(StgitObject): os.mkdir(self._dir()) self.create_empty_field('bottom') self.create_empty_field('top') - + def delete(self): for f in os.listdir(self._dir()): os.remove(os.path.join(self._dir(), f))
@@ -369,7 +369,11 @@ class PatchorderCache: saved in its patchorder file.""" def __init__(self, series): self.__series = series + self.__file = os.path.join(self.__series._dir(), 'patchorder') self.__invalidate() + def delete_file(self): + if os.path.isfile(self.__file): + os.remove(self.__file) def __invalidate(self): self.__patchnames = None self.__position = None
@@ -379,9 +383,8 @@ class PatchorderCache: self.__patchnames = [] self.__position = {} - pof = os.path.join(self.__series._dir(), 'patchorder') - if os.path.isfile(pof): - for line in file(pof): + if os.path.isfile(self.__file): + for line in file(self.__file): name = line.strip() assert not name in self.__position self.__position[name] = len(self.__patchnames)
@@ -404,60 +407,200 @@ class PatchorderCache: pos2 = self.__position.get(name2, largepos) return cmp((pos1, name1), (pos2, name2)) +class UninterestingCache: + """Keeps track of a set of commits that do not reach any patches. + These are used to speed up the detection of unapplied patches. + + Specifically, this is at all times the set of commits c that + fulfill the following two criteria: + + * c does not reach any patch + + * c is the parent of a patch + + """ + def __init__(self, series): + self.__series = series + self.__uninteresting = None + self.__filename = os.path.join(self.__series._dir(), 'uninteresting') + def __invalidate(self): + self.__uninteresting = None + self.delete_file() + def delete_file(self): + if os.path.isfile(self.__filename): + os.remove(self.__filename) + def __other_patches(self, patchname): + """All patches except the named one.""" + ref2hash = read_refs(self.__series.get_branch()) + return [self.__series.get_patch(ref) + for ref in ref2hash.iterkeys() + if ref and ref != patchname] + def __write_file(self): + """Write the uninteresting commits to file.""" + try: + f = file(self.__filename, 'w') + for u in self.__uninteresting: + f.write('%s\n' % u) + f.close() + except IOError: + pass # this isn't fatal -- the directory is probably missing + def __read_file(self): + """Read the uninteresting commits from file. Return true on + success, false on failure.""" + if not os.path.isfile(self.__filename): + return False + self.__uninteresting = Set() + for line in file(self.__filename): + self.__uninteresting.add(line.strip()) + return True + def __cache_file(self): + """Try to cache the uninteresting commits using only the cache + file. Return true on success, false on failure.""" + if self.__uninteresting != None: + return True # already cached + return self.__read_file() + def __cache(self): + """Cache the uninteresting commits, recomputing them if + necessary.""" + if self.__cache_file(): + return + self.__compute_uninteresting() + self.__write_file() + def __compute_uninteresting(self): + """Compute a reasonable set of uninteresting commits from + scratch. This is expensive.""" + out.start('Finding uninteresting commits') + ref2hash = read_refs(self.__series.get_branch()) + patches = Set([sha1 for ref, sha1 in ref2hash.iteritems() if ref]) + interesting, uninteresting = Set(), Set() + + # Iterate over all commits. We are guaranteed to see each + # commit before any of its children. + for line in git._output_lines( + 'git-rev-list --topo-order --reverse --parents --all'): + commits = line.split() + commit, parents = commits[0], Set(commits[1:]) + + # Patches are interesting. + if commit in patches: + interesting.add(commit) + + # The parents of a patch are uninteresting unless they + # are interesting. + for p in parents: + if not p in interesting: + uninteresting.add(p) + continue + + # Commits with interesting parents are interesting. + if interesting.intersection(parents): + interesting.add(commit) + self.__uninteresting = uninteresting + out.done() + def create_patch(self, name, top, bottom): + """The given patch has been created. Update the uninterested + state to maintain the invariant.""" + if not self.__cache_file(): + return # not cached + + # New patch inserted just below an existing bottommost patch: + # need to move the uninteresting commit down one step. + if top in self.__uninteresting: + self.__uninteresting.remove(top) + self.__uninteresting.add(bottom) + self.__write_file() + return + + # New patch inserted next to an existing non-bottommost patch: + # don't need to do anything. + existing_patches = self.__other_patches(name) + tops = Set([p.get_top() for p in existing_patches]) + bottoms = Set([p.get_bottom() for p in existing_patches]) + if bottom in bottoms or bottom in tops or top in bottoms: + return + + # The new patch is not adjacent to an existing patch. We'd + # need to first get rid of any uninteresting commit that + # reaches this patch, and then mark the patch's bottom + # uninteresting if it doesn't reach any other patch. This is a + # lot of work, so we chicken out and blow the whole cache + # instead. + self.__invalidate() + def delete_patch(self, name, top, bottom): + """The given patch has been deleted. Update the uninterested + state to maintain the invariant.""" + if not self.__cache_file(): + return # not cached + + # If this patch reaches another patch, there's nothing to do. + if not bottom in self.__uninteresting: + return + + # If another patch has the same bottom, it's still + # uninteresting and there's nothing more to do. + other_patches = self.__other_patches(name) + for p in other_patches: + if p.get_bottom() == bottom: + return + + # If there are other patches on top of this one, their bottoms + # (this patch's top) become uninteresting in place of this + # patch's bottom. + for p in other_patches: + if p.get_bottom() == top: + self.__uninteresting.remove(bottom) + self.__uninteresting.add(top) + self.__write_file() + return + + # The bottom of this patch is no longer uninteresting. But + # there might be other patches that reach it, whose bottoms + # would need to be marked uninteresting. That would require an + # expensive reachability analysis. + self.__invalidate() + def get(self): + self.__cache() + return self.__uninteresting + def read_refs(branch): """Return a mapping from patches and branch head to hashes for a given branch. The patches are listed by name; the branch head is None.""" refs = {} patchpat = re.compile(r'^refs/patches/%s/([^\.]+)$' % branch) + head = 'refs/heads/%s' % branch for line in git._output_lines('git-show-ref'): sha1, ref = line.split() m = re.match(patchpat, ref) if m: refs[m.group(1)] = sha1 - elif ref == 'refs/heads/%s' % branch: + elif ref == head: refs[None] = sha1 + if not None in refs: + raise StackException, 'Could not find %s' % head return refs -def unapplied_patches(ref2hash): +def get_patches(ref2hash, uninteresting): """Given a map of patch names (and the branch head, keyed by None) - to hashes, return the set of unapplied patches.""" - hash2refs = {} - for r, h in ref2hash.iteritems(): - hash2refs.setdefault(h, Set()).add(r) - + to hashes, return the list of applied patches and the set of + unapplied patches. The second parameter is a set of commit objects + that do not reach any patch.""" + applied = [] unapplied = Set() - for line in git._output_lines( - 'git-rev-list --stdin', - ('%s%s\n' % (['', '^'][ref == None], sha1) - for ref, sha1 in ref2hash.iteritems())): - for ref in hash2refs.get(line.strip(), []): - unapplied.add(ref) - return unapplied - -def sort_applied_patches(ref2hash): - """Given a map of patch names (and the branch head, keyed by None) - to hashes, return a list with the applied patches in stack order. - All patches in the map must be applied.""" - hash2refs = {} + hash2patches = {} for r, h in ref2hash.iteritems(): - if r != None: - hash2refs.setdefault(h, Set()).add(r) + if r: + hash2patches.setdefault(h, Set()).add(r) + unapplied.add(r) - missing = Set(ref for ref in ref2hash.iterkeys() if ref != None) - if not missing: - return [] - applied = [] - grl = popen2.Popen3('git-rev-list %s' % ref2hash[None], True) - for line in grl.fromchild: - for ref in hash2refs.get(line.strip(), []): + for line in git._output_lines( + 'git-rev-list --topo-order --stdin', ['%s\n' % ref2hash[None]] + + ['^%s\n' % u for u in uninteresting]): + for ref in hash2patches.get(line.strip(), []): applied.append(ref) - missing.remove(ref) - if not missing: - applied.reverse() - return applied - - raise StackException, 'Could not find patches: %s' % ', '.join(missing) + unapplied.remove(ref) + applied.reverse() + return applied, unapplied class AppliedCache: """An object that keeps track of the appliedness and order of the
@@ -465,7 +608,11 @@ class AppliedCache: def __init__(self, series): self.__series = series self.__order = PatchorderCache(series) + self.__uninteresting = UninterestingCache(series) self.__invalidate() + def delete_files(self): + for sub in [self.__uninteresting, self.__order]: + sub.delete_file() def get_applied(self): self.__cache() return self.__applied
@@ -484,6 +631,17 @@ class AppliedCache: self.__write_patchorder() return raise StackException, 'Unknown patch "%s"' % oldname + def new(self, name, top, bottom): + """Create new patch.""" + self.__uninteresting.create_patch(name, top, bottom) + def delete(self, name, top, bottom): + """Delete a patch.""" + self.__uninteresting.delete_patch(name, top, bottom) + def change(self, name, old_top, old_bottom, new_top, new_bottom): + """Change a patch.""" + if (new_top, new_bottom) != (old_top, old_bottom): + self.new(name, new_top, new_bottom) + self.delete(name, old_top, old_bottom) def __write_patchorder(self): self.__order.set_patchorder(self.get_applied() + self.get_unapplied()) def set_patchorder(self, new_order):
@@ -502,11 +660,8 @@ class AppliedCache: def __cache(self): if self.__cached(): return - patches = read_refs(self.__series.get_branch()) - unapplied = unapplied_patches(patches) - for patch in unapplied: - del patches[patch] - self.__applied = sort_applied_patches(patches) + self.__applied, unapplied = get_patches( + read_refs(self.__series.get_branch()), self.__uninteresting.get()) self.__unapplied = list(unapplied) self.__unapplied.sort(self.__order.cmp)
@@ -838,6 +993,7 @@ class Series(StgitObject): os.remove(self.__hidden_file) if os.path.exists(self._dir()+'/orig-base'): os.remove(self._dir()+'/orig-base') + self.__applied_cache.delete_files() if not os.listdir(self.__patch_dir): os.rmdir(self.__patch_dir)
@@ -940,16 +1096,20 @@ class Series(StgitObject): patch = self.get_patch(name) old_bottom = patch.get_old_bottom() old_top = patch.get_old_top() + curr_bottom = patch.get_bottom() + curr_top = patch.get_top() # the bottom of the patch is not changed by refresh. If the # old_bottom is different, there wasn't any previous 'refresh' # command (probably only a 'push') - if old_bottom != patch.get_bottom() or old_top == patch.get_top(): + if old_bottom != curr_bottom or old_top == curr_top: raise StackException, 'No undo information available' git.reset(tree_id = old_top, check_out = False) if patch.restore_old_boundaries(): self.log_patch(patch, 'undo') + self.__applied_cache.change(name, curr_top, curr_bottom, + old_top, old_bottom) def new_patch(self, name, message = None, can_edit = True, unapplied = False, show_patch = False,
@@ -982,14 +1142,11 @@ class Series(StgitObject): patch = self.get_patch(name) patch.create() - if bottom: - patch.set_bottom(bottom) - else: - patch.set_bottom(head) - if top: - patch.set_top(top) - else: - patch.set_top(head) + bottom = bottom or head + top = top or head + patch.set_bottom(bottom) + patch.set_top(top) + self.__applied_cache.new(name, top, bottom) patch.set_description(descr) patch.set_authname(author_name)
@@ -1016,15 +1173,16 @@ class Series(StgitObject): def delete_patch_data(self, name): """Deletes the stgit data for a patch.""" patch = Patch(name, self.__patch_dir, self.__refs_dir) + top, bottom = patch.get_top(), patch.get_bottom() # save the commit id to a trash file - write_string(os.path.join(self.__trash_dir, name), patch.get_top()) + write_string(os.path.join(self.__trash_dir, name), top) patch.delete() if self.patch_hidden(name): self.unhide_patch(name) - return patch + self.__applied_cache.delete(name, top, bottom) def delete_patch(self, name): """Deletes a patch
@@ -1084,6 +1242,7 @@ class Series(StgitObject): top_tree = git.get_commit(top).get_tree() + old_top = top top = git.commit(message = descr, parents = [head], cache_update = False, tree_id = top_tree,
@@ -1097,6 +1256,9 @@ class Series(StgitObject): patch.set_bottom(head, backup = True) patch.set_top(top, backup = True) + self.__applied_cache.change( + name, old_top = old_top, old_bottom = bottom, + new_top = top, new_bottom = head) self.log_patch(patch, 'push(f)') else: top = head
@@ -1154,6 +1316,7 @@ class Series(StgitObject): # need an empty commit patch.set_bottom(head, backup = True) patch.set_top(head, backup = True) + self.__applied_cache.change(name, top, bottom, head, head) modified = True elif head == bottom: # reset the backup information. No need for logging
@@ -1166,6 +1329,7 @@ class Series(StgitObject): # The current patch is empty after merge. patch.set_bottom(head, backup = True) patch.set_top(head, backup = True) + self.__applied_cache.change(name, top, bottom, head, head) # Try the fast applying first. If this fails, fall back to the # three-way merge
@@ -1211,6 +1375,8 @@ class Series(StgitObject): patch = self.get_patch(name) old_bottom = patch.get_old_bottom() old_top = patch.get_old_top() + curr_bottom = patch.get_bottom() + curr_top = patch.get_top() # the top of the patch is changed by a push operation only # together with the bottom (otherwise the top was probably
@@ -1222,6 +1388,8 @@ class Series(StgitObject): git.reset() self.pop_patch(name) ret = patch.restore_old_boundaries() + self.__applied_cache.change(name, curr_top, curr_bottom, + old_top, old_bottom) if ret: self.log_patch(patch, 'undo')
Re: [StGIT PATCH 0/6] New and improved DAG appliedness series
In reply to Karl HasselströmHi Karl,
Quoted 2 lines · Karl Hasselström
This took a while, but here it is. (Actually, I finished this about a week ago, but had no Internet connection so I couldn't send it.)
Is this the latest version of the DAG patches, or is there maybe a public repo where you push your work ?
It happens that my refactorings touches virtually everything, so there will be conflicts, and the best thing to do is probably that I rebase my work on yours.
Best regards,
Signature · 1 line
Yann
Re: [StGIT PATCH 0/6] New and improved DAG appliedness series
Quoted 8 lines · Yann Dirson
Quoted 3 lines · Karl Hasselström
This took a while, but here it is. (Actually, I finished this about a week ago, but had no Internet connection so I couldn't send it.)
Is this the latest version of the DAG patches, or is there maybe a public repo where you push your work ?
This is the latest version, and no, I don't yet have a public repo that I push this stuff to.
I've been travelling a lot the last few weeks, and I'm not quite done yet, so I haven't had time to even follow the mailing list properly, but after that I plan to start a pu-ish (rebasing) integration branch for the patches that I, you, and others post to the list.
Quoted 1 line
It happens that my refactorings touches virtually everything,
I noticed. :-)
Quoted 1 line
so there will be conflicts,
:-)
Quoted 1 line
and the best thing to do is probably that I rebase my work on yours.
Thanks for the vote of confidence. Please go ahead; as I said, you already have the latest version of my series, and it may be a while yet before I have much time to burn on StGIT.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Quoted 6 lines · Catalin Marinas
Quoted 4 lines · Karl Hasselström
The name of the current patch, if any, is always the last line of patches/<branch>/applied (and there is no current patch if and only if the "applied" file is empty). So use that instead, and stop having to worry about keeping the redundant "current" file up-to-date.
Quoted 7 lines
I applied this patch. Could you also send me a patch for the bash-completion script as it uses this file?
I think the self.__current_file (same for the base file removed in a different patch) should still be available in the Series object and removed when deleting a branch, otherwise you get a "Series directory .. is not empty" exception.
Shouldn't we also migrate to new format as soon as we need to touch a data - in this case, whenever we push/pop ?
Or maybe declare a new "stgit stack format version" ? Currently we have "stg branch --convert", which switches between a "new" and an "old" format which noone probably uses any more. What about versionning the on-disk format, and possibly provide the "convert" functionnality back and forth between one format and the next, with formal documentation about which version works with which stack format ?
Best regards,
Signature · 1 line
Yann.
Quoted 9 lines · Yann Dirson
Quoted 4 lines · Catalin Marinas
I think the self.__current_file (same for the base file removed in a different patch) should still be available in the Series object and removed when deleting a branch, otherwise you get a "Series directory .. is not empty" exception.
Shouldn't we also migrate to new format as soon as we need to touch a data - in this case, whenever we push/pop ?
Quoted 7 lines
Or maybe declare a new "stgit stack format version" ? Currently we have "stg branch --convert", which switches between a "new" and an "old" format which noone probably uses any more. What about versionning the on-disk format, and possibly provide the "convert" functionnality back and forth between one format and the next, with formal documentation about which version works with which stack format ?
I think it would be useful to have a version file (probably per branch) and just upgrade when a mismatch is detected (in the __init__ function). The other option is to keep ignoring the unused files until the branch is deleted but we might make a change at some point that would break things.
We should write successive convert() functions and keep all of them in case one skips an intermediate version.
Signature · 1 line
Catalin
Quoted 3 lines · Catalin Marinas
I think it would be useful to have a version file (probably per branch) and just upgrade when a mismatch is detected (in the
__init__function).
Sounds reasonable, but I'd rather keep that in the config file (eg. branch.<name>.stgit.formatversion).
Best regards,
Signature · 1 line
Yann.
Quoted 8 lines · Yann Dirson
Quoted 3 lines · Catalin Marinas
I think it would be useful to have a version file (probably per branch) and just upgrade when a mismatch is detected (in the
__init__function).Sounds reasonable, but I'd rather keep that in the config file (eg. branch.<name>.stgit.formatversion).
I agree that explicit versioning would be a good idea -- doing explicit upgrades at well-defined points is good headache prevention.
And I agree that the config file is a good place to put it.
I'll probably have time to whip up a patch later today. I think I'll call the old "old" format 0, the old "new" format 1, and then use successive integers from then on. I'll make a single version bump for the format changes you've alreay applied, and re-do the format-changing patches you haven't applied yet so that they have version bumping integrated.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
cover Metadata format versioning
Quoted 1 line · Karl Hasselström
I'll probably have time to whip up a patch later today.
OK, so this turned out to be a slight miscalculation. But here it is, with a test! The test contains two small tarballs, so I had to whip up binary patch support as well.
Quoted 3 lines
I'll make a single version bump for the format changes you've alreay applied, and re-do the format-changing patches you haven't applied yet so that they have version bumping integrated.
This contains a single version bump (1 -> 2) for the applied changes, but i haven't updated the DAG patch to use this yet. That's for another day.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/5 Fix config caching so that get, set, get works
The config caching was never invalidated or updated, which caused the two gets to always return the same value regardless of the value passed to set.
---
stgit/config.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
stgit/config.py +3 -0
@@ -99,12 +99,15 @@ class GitConfig: def rename_section(self, from_name, to_name): self.__run('git-repo-config --rename-section', [from_name, to_name]) + self.__cache.clear() def set(self, name, value): self.__run('git-repo-config', [name, value]) + self.__cache[name] = value def unset(self, name): self.__run('git-repo-config --unset', [name]) + self.__cache[name] = None def sections_matching(self, regexp): """Takes a regexp with a single group, matches it against all
PATCH 2/5 Have only a single command in each test_expect_failure
In reply to Karl HasselströmOtherwise, we can't know which one failed.
---
t/t1000-branch-create.sh | 71 ++++++++++++++++++++++++++++------------------ 1 files changed, 43 insertions(+), 28 deletions(-)
t/t1000-branch-create.sh +43 -28
@@ -12,57 +12,72 @@ Exercises the "stg branch" commands. stg init +test_expect_success \ + 'Create a spurious refs/patches/ entry' ' + find .git -name foo | xargs rm -rf && + touch .git/refs/patches/foo +' + test_expect_failure \ - 'Try to create an stgit branch with a spurious refs/patches/ entry' \ - 'find .git -name foo | xargs rm -rf && - touch .git/refs/patches/foo && - stg branch -c foo + 'Try to create an stgit branch with a spurious refs/patches/ entry' ' + stg branch -c foo +' + +test_expect_success \ + 'Check that no part of the branch was created' ' + test "`find .git -name foo | tee /dev/stderr`" = ".git/refs/patches/foo" && + ( grep foo .git/HEAD; test $? = 1 ) ' test_expect_success \ - 'Check no part of the branch was created' \ - 'test "`find .git -name foo | tee /dev/stderr`" = ".git/refs/patches/foo" && - ( grep foo .git/HEAD; test $? = 1 ) + 'Create a spurious patches/ entry' ' + find .git -name foo | xargs rm -rf && + touch .git/patches/foo ' test_expect_failure \ - 'Try to create an stgit branch with a spurious patches/ entry' \ - 'find .git -name foo | xargs rm -rf && - touch .git/patches/foo && - stg branch -c foo + 'Try to create an stgit branch with a spurious patches/ entry' ' + stg branch -c foo ' test_expect_success \ - 'Check no part of the branch was created' \ - 'test "`find .git -name foo | tee /dev/stderr`" = ".git/patches/foo" && - ( grep foo .git/HEAD; test $? = 1 ) + 'Check that no part of the branch was created' ' + test "`find .git -name foo | tee /dev/stderr`" = ".git/patches/foo" && + ( grep foo .git/HEAD; test $? = 1 ) +' + +test_expect_success \ + 'Create a git branch' ' + find .git -name foo | xargs rm -rf && + cp .git/refs/heads/master .git/refs/heads/foo ' test_expect_failure \ - 'Try to create an stgit branch with an existing git branch by that name' \ - 'find .git -name foo | xargs rm -rf && - cp .git/refs/heads/master .git/refs/heads/foo && - stg branch -c foo + 'Try to create an stgit branch with an existing git branch by that name' ' + stg branch -c foo ' test_expect_success \ - 'Check no part of the branch was created' \ - 'test "`find .git -name foo | tee /dev/stderr`" = ".git/refs/heads/foo" && - ( grep foo .git/HEAD; test $? = 1 ) + 'Check that no part of the branch was created' ' + test "`find .git -name foo | tee /dev/stderr`" = ".git/refs/heads/foo" && + ( grep foo .git/HEAD; test $? = 1 ) ' +test_expect_success \ + 'Create an invalid refs/heads/ entry' ' + find .git -name foo | xargs rm -rf && + touch .git/refs/heads/foo +' test_expect_failure \ - 'Try to create an stgit branch with an invalid refs/heads/ entry' \ - 'find .git -name foo | xargs rm -rf && - touch .git/refs/heads/foo && - stg branch -c foo + 'Try to create an stgit branch with an invalid refs/heads/ entry' ' + stg branch -c foo ' test_expect_success \ - 'Check no part of the branch was created' \ - 'test "`find .git -name foo | tee /dev/stderr`" = ".git/refs/heads/foo" && - ( grep foo .git/HEAD; test $? = 1 ) + 'Check that no part of the branch was created' ' + test "`find .git -name foo | tee /dev/stderr`" = ".git/refs/heads/foo" && + ( grep foo .git/HEAD; test $? = 1 ) ' test_done
PATCH 3/5 Upgrade old StGIT branches to new-format metadata
In reply to Karl HasselströmThere used to be a "stg branch --convert" command that switched between "old" and "new" format metadata. But my recent metadata cleanup patches introduced a "new new" format, and more are hopefully on the way, so it was time to start versioning the metadata format explicitly in order to avoid future headaches.
This patch removes the "stg branch --convert" command, and makes StGIT automatically upgrade older formats to the latest format. It stores the format (as an integer) in the config file. The current metadata format version number is 2 (the "old" format is 0, and the "new" format is 1).
---
Documentation/stg-branch.txt | 4 - stgit/commands/branch.py | 11 --- stgit/stack.py | 153 ++++++++++++++++++++++++------------------ 3 files changed, 86 insertions(+), 82 deletions(-)
Documentation/stg-branch.txt +0 -4
@@ -20,7 +20,6 @@ SYNOPSIS 'stg' branch --protect [<branch>] 'stg' branch --unprotect [<branch>] 'stg' branch --delete [--force] <branch> -'stg' branch --convert DESCRIPTION -----------
@@ -91,9 +90,6 @@ the "master" branch if it exists. Branch "master" is treated specially (see bug #8732), in that only the StGIT metadata are removed, the GIT branch itself is not destroyed. -'stg' branch --convert:: - Switch current stack between old and new format. - OPTIONS -------
stgit/commands/branch.py +0 -11
@@ -45,9 +45,6 @@ options = [make_option('-c', '--create', make_option('--clone', help = 'clone the contents of the current branch', action = 'store_true'), - make_option('--convert', - help = 'switch between old and new format branches', - action = 'store_true'), make_option('--delete', help = 'delete an existing development branch', action = 'store_true'),
@@ -186,14 +183,6 @@ def func(parser, options, args): return - elif options.convert: - - if len(args) != 0: - parser.error('incorrect number of arguments') - - crt_series.convert() - return - elif options.delete: if len(args) != 1:
stgit/stack.py +86 -67
211 lines not on this page · raw message
PATCH 4/5 Test the format version upgrade code
In reply to Karl HasselströmThis test contains tarballs of repositories created with older versions of StGIT. It also contains the script used to generate them, but at some point we will lose the ability to easily run old versions -- for example, if git changes incompatibly -- so tarballs will be the only practical option for sufficiently old versions.
---
t/t4000-upgrade.sh | 40 ++++++++++++++++++++++++ t/t4000-upgrade/.gitignore | 4 ++ t/t4000-upgrade/0.12.tar.gz | Bin t/t4000-upgrade/0.8.tar.gz | Bin t/t4000-upgrade/make-repo.sh | 71 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 0 deletions(-)
t/t4000-upgrade.sh new file +40 -0
@@ -0,0 +1,40 @@ +#!/bin/sh +# +# Copyright (c) 2007 Karl Hasselström +# + +test_description='Make sure that we can use old StGIT repositories' + +. ./test-lib.sh + +for ver in 0.12 0.8; do + + tar zxf ../t4000-upgrade/$ver.tar.gz + cd $ver + + test_expect_success \ + "v$ver: Check the list of applied and unapplied patches" ' + [ "$(echo $(stg applied))" = "p0 p1 p2" ] && + [ "$(echo $(stg unapplied))" = "p3 p4" ] + ' + + test_expect_success \ + "v$ver: Make sure the 'description' file is no longer there" ' + [ ! -e .git/patches/master/description ] && + [ "$(echo $(git config branch.master.description))" = "cool branch" ] + ' + + test_expect_success \ + "v$ver: Make sure the 'current' file is no longer there" ' + [ ! -e .git/patches/master/current ] + ' + + test_expect_success \ + "v$ver: Make sure the base ref is no longer there" ' + ! git show-ref --verify --quiet refs/bases/master + ' + + cd .. +done + +test_done
t/t4000-upgrade/.gitignore new file +4 -0
@@ -0,0 +1,4 @@ +/stgit-0.8 +/stgit-0.12 +/0.8 +/0.12
t/t4000-upgrade/0.12.tar.gz new file binary +0 -0
t/t4000-upgrade/0.8.tar.gz new file binary +0 -0
t/t4000-upgrade/make-repo.sh new file +71 -0
71 lines not on this page · raw message
PATCH 5/5 Add --binary flag to commands that generate diffs
In reply to Karl HasselströmThis just passes the --binary option to git-diff-*, which causes the generated diffs to contain an applyable diff even when binary files differ. It's necessary to do this if you want to mail patches to binary files.
---
stgit/commands/diff.py | 6 +++++- stgit/commands/export.py | 5 ++++- stgit/commands/mail.py | 6 +++++- stgit/git.py | 16 ++++++++++++---- 4 files changed, 26 insertions(+), 7 deletions(-)
stgit/commands/diff.py +5 -1
@@ -44,6 +44,9 @@ shows the specified patch (defaulting to the current one).""" options = [make_option('-r', '--range', metavar = 'rev1[..[rev2]]', dest = 'revs', help = 'show the diff between revisions'), + make_option('--binary', + help = 'output a diff even for binary files', + action = 'store_true'), make_option('-s', '--stat', help = 'show the stat instead of the diff', action = 'store_true')]
@@ -79,6 +82,7 @@ def func(parser, options, args): if options.stat: print git.diffstat(args, git_id(rev1), git_id(rev2)) else: - diff_str = git.diff(args, git_id(rev1), git_id(rev2)) + diff_str = git.diff(args, git_id(rev1), git_id(rev2), + binary = options.binary) if diff_str: pager(diff_str)
stgit/commands/export.py +4 -1
@@ -62,6 +62,9 @@ options = [make_option('-d', '--dir', help = 'Use FILE as a template'), make_option('-b', '--branch', help = 'use BRANCH instead of the default one'), + make_option('--binary', + help = 'output a diff even for binary files', + action = 'store_true'), make_option('-s', '--stdout', help = 'dump the patches to the standard output', action = 'store_true')]
@@ -172,7 +175,7 @@ def func(parser, options, args): # write the diff git.diff(rev1 = patch.get_bottom(), rev2 = patch.get_top(), - out_fd = f) + out_fd = f, binary = options.binary) if not options.stdout: f.close() patch_no += 1
stgit/commands/mail.py +5 -1
@@ -120,6 +120,9 @@ options = [make_option('-a', '--all', help = 'username for SMTP authentication'), make_option('-b', '--branch', help = 'use BRANCH instead of the default one'), + make_option('--binary', + help = 'output a diff even for binary files', + action = 'store_true'), make_option('-m', '--mbox', help = 'generate an mbox file instead of sending', action = 'store_true')]
@@ -390,7 +393,8 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options): # for backward template compatibility 'endofheaders': '', 'diff': git.diff(rev1 = git_id('%s//bottom' % patch), - rev2 = git_id('%s//top' % patch)), + rev2 = git_id('%s//top' % patch), + binary = options.binary), 'diffstat': git.diffstat(rev1 = git_id('%s//bottom'%patch), rev2 = git_id('%s//top' % patch)), # for backward template compatibility
stgit/git.py +12 -4
@@ -771,20 +771,28 @@ def status(files = None, modified = False, new = False, deleted = False, else: print '%s' % fs[1] -def diff(files = None, rev1 = 'HEAD', rev2 = None, out_fd = None): +def diff(files = None, rev1 = 'HEAD', rev2 = None, out_fd = None, + binary = False): """Show the diff between rev1 and rev2 """ if not files: files = [] + args = [] + if binary: + args.append('--binary') + if rev1 and rev2: - diff_str = _output(['git-diff-tree', '-p', rev1, rev2, '--'] + files) + diff_str = _output(['git-diff-tree', '-p'] + args + + [rev1, rev2, '--'] + files) elif rev1 or rev2: refresh_index() if rev2: - diff_str = _output(['git-diff-index', '-p', '-R', rev2, '--'] + files) + diff_str = _output(['git-diff-index', '-p', '-R'] + + args + [rev2, '--'] + files) else: - diff_str = _output(['git-diff-index', '-p', rev1, '--'] + files) + diff_str = _output(['git-diff-index', '-p'] + + args + [rev1, '--'] + files) else: diff_str = ''
Re: [StGIT PATCH 5/5] Add --binary flag to commands that generate diffs
Quoted 4 lines · Karl Hasselström
This just passes the --binary option to git-diff-*, which causes the generated diffs to contain an applyable diff even when binary files differ. It's necessary to do this if you want to mail patches to binary files.
I applied this patch but is there anything wrong if we have this option on by default, at least for some commands? Maybe we don't need it for 'show' and 'diff' but we definitely need it for 'mail' and 'export'.
There is also git.apply_diff() which calls git.diff(). This is first tried when pushing a patch and followed by a three-way merged if it fails. I think we should always have the --binary option in this case.
Signature · 1 line
Catalin
Re: [StGIT PATCH 5/5] Add --binary flag to commands that generate diffs
Quoted 11 lines · Catalin Marinas
Quoted 4 lines · Karl Hasselström
This just passes the --binary option to git-diff-*, which causes the generated diffs to contain an applyable diff even when binary files differ. It's necessary to do this if you want to mail patches to binary files.
I applied this patch but is there anything wrong if we have this option on by default, at least for some commands? Maybe we don't need it for 'show' and 'diff' but we definitely need it for 'mail' and 'export'.
I'd be fine with that.
Quoted 4 lines
There is also
git.apply_diff()which callsgit.diff(). This is first tried when pushing a patch and followed by a three-way merged if it fails. I think we should always have the --binary option in this case.
Yes, that sounds good.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
cover Bash prompt updates
In reply to Karl HasselströmHere is a fix to update the bash prompt so it does not use the obsolete current file anymore.
Part 2 is my version which uses a different format, mostly because '/' can be part of the branch name.
-- robin
PATCH 1/2 Update the bash prompt from 'applied' instead of the obsolete 'current'
---
contrib/stgbashprompt.sh | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
contrib/stgbashprompt.sh +2 -2
@@ -8,8 +8,8 @@ if [ "$PS1" ]; then git_dir=$(git-rev-parse --git-dir 2> /dev/null) || return ref=$(git-symbolic-ref HEAD 2> /dev/null) || return br=${ref#refs/heads/} - top=$(cat $git_dir/patches/$br/current 2>/dev/null) \ - && top="/$top" + top=$(tail -1 $git_dir/patches/$br/applied 2>/dev/null) \ + && top="/$top"; echo "[$br$top]" } PS1='\u@\h:$(__prompt_git)\W\$ '
Re: [StGit PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current'
Note that "tail -1" gives a warning with newer versions, "tail -n 1" should be the proper call.
Also I'm not sure it is a good way to look at "applied" file, since Karl IIRC has plans to change this. Better call "stg top" and not touch that again :)
Quoted 29 lines · Robin Rosenberg
Signed-off-by Robin Rosenberg <[email protected]>---
contrib/stgbashprompt.sh | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)contrib/stgbashprompt.sh +2
-3@@ -8,8 +8,8 @@ if [ "$PS1" ]; then git_dir=$(git-rev-parse --git-dir 2> /dev/null) || return ref=$(git-symbolic-ref HEAD 2> /dev/null) || return br=${ref#refs/heads/} - top=$(cat $git_dir/patches/$br/current 2>/dev/null) \ - && top="/$top" + top=$(tail -1 $git_dir/patches/$br/applied 2>/dev/null) \ + && top="/$top"; echo "[$br$top]" } PS1='\u@\h:$(__prompt_git)\W\$ ' -To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html!DSPAM:4650aff673931961316905!
PATCH 1/2 Update the bash prompt from 'applied' instead of the obsolete 'current'
s�ndag 20 maj 2007 skrev Yann Dirson:
Quoted 2 lines
Note that "tail -1" gives a warning with newer versions, "tail -n 1" should be the proper call.
My man page doesn't mention -N being deprecated, but ok since -n 1 seems to work here too.
Quoted 3 lines
Also I'm not sure it is a good way to look at "applied" file, since Karl IIRC has plans to change this. Better call "stg top" and not touch that again :)
Calling stg is too slow to be be used here. I that command in my first draft for this function and people complained (see the thread named "Bash snippet to show branch and patch in bash prompt"). It takes ~ 0.15s on here which is very noticable, barely below my pain threshold.
We'll update the prompt when and if Karl breaks this.
It'd probably drain my battery too :/
-- robin
contrib/stgbashprompt.sh | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
contrib/stgbashprompt.sh +2 -2
@@ -8,8 +8,8 @@ if [ "$PS1" ]; then git_dir=$(git-rev-parse --git-dir 2> /dev/null) || return ref=$(git-symbolic-ref HEAD 2> /dev/null) || return br=${ref#refs/heads/} - top=$(cat $git_dir/patches/$br/current 2>/dev/null) \ - && top="/$top" + top=$(tail -n 1 $git_dir/patches/$br/applied 2>/dev/null) \ + && top="/$top"; echo "[$br$top]" } PS1='\u@\h:$(__prompt_git)\W\$ '
Re: [PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current'
Quoted 6 lines · Robin Rosenberg
söndag 20 maj 2007 skrev Yann Dirson:
Quoted 3 lines
Also I'm not sure it is a good way to look at "applied" file, since Karl IIRC has plans to change this. Better call "stg top" and not touch that again :)
Quoted 7 lines
Calling stg is too slow to be be used here. I that command in my first draft for this function and people complained (see the thread named "Bash snippet to show branch and patch in bash prompt"). It takes ~ 0.15s on here which is very noticable, barely below my pain threshold.
We'll update the prompt when and if Karl breaks this.
Yes, I can confirm that I'm hard at work breaking this. :-) I'm trying out a way to get around the performance bug Catalin found, but I didn't have time to finish it yesterday.
If that work is included, you could simply find the top patch by doing git-show-ref and figuring out which patch has the same sha1 as HEAD.
But it sucks that stg starts so slowly. It has gotten better, I believe (I think Catalin did some work here?), but 150 ms doesn't really qualify as "instantaneous".
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Re: [PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current'
Quoted 7 lines · Karl Hasselström
Quoted 6 lines · Robin Rosenberg
Calling stg is too slow to be be used here. I that command in my first draft for this function and people complained (see the thread named "Bash snippet to show branch and patch in bash prompt"). It takes ~ 0.15s on here which is very noticable, barely below my pain threshold.
Quoted 5 lines
Quoted 1 line
We'll update the prompt when and if Karl breaks this.
Yes, I can confirm that I'm hard at work breaking this. :-) I'm trying out a way to get around the performance bug Catalin found, but I didn't have time to finish it yesterday.
My plan is to release a 0.13 version pretty soon but without the DAG patches as we might have to test them a bit more. The release after 0.13 I'd like to be a 1.0-rc1 (including the DAG patches) unless we have some other major changes pending.
Quoted 3 lines
But it sucks that stg starts so slowly. It has gotten better, I believe (I think Catalin did some work here?), but 150 ms doesn't really qualify as "instantaneous".
I don't think we can get much slower than this. I modified stg to only load the modules needed for a given command but it still takes around 150ms for a command like 'top'. I don't know any other python tricks to make it start faster.
BTW, any of you would like to get added as a member to gna.org/projects/stgit (there are no advantages, only e-mail updates for filed bug reports)?
Regards.
Signature · 1 line
Catalin
Re: [PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current'
Quoted 2 lines · Catalin Marinas
My plan is to release a 0.13 version pretty soon but without the DAG patches as we might have to test them a bit more.
That's reasonable.
Quoted 2 lines
The release after 0.13 I'd like to be a 1.0-rc1 (including the DAG patches) unless we have some other major changes pending.
It'd be great to do away with the need to "stg init", but that shouldn't really be a major change (but I haven't started looking at it yet). It would be nice if 1.0 had documentation that didn't have to mention "stg init".
Quoted 1 line
I don't think we can get much slower than this.
Oh yes we can ... :-)
Quoted 3 lines
I modified stg to only load the modules needed for a given command but it still takes around 150ms for a command like 'top'. I don't know any other python tricks to make it start faster.
I don't either. We might consider having plumbing written in C or something, and make sure that the plumbing can be called directly if there's need, but it's going to complicate things greatly compared to pure Python.
Quoted 3 lines
BTW, any of you would like to get added as a member to gna.org/projects/stgit (there are no advantages, only e-mail updates for filed bug reports)?
Free bug reports? Sure, I'm in! (I just created a Gna! account: kha)
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Re: [PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current'
Quoted 3 lines · Karl Hasselström
We might consider having plumbing written in C or something, and make sure that the plumbing can be called directly if there's need, but it's going to complicate things greatly compared to pure Python.
What I'm (foggily) envisioning here is to rewrite parts of StGIT (as little as possible) as a C library (libstgit.so?), and call the library both from the Python code, and from a "plumbing" C program (stgit-helper?). We should not try to make the library API stable, just like the current git library.
There are two kinds of things we'd want to have in the library: (1) things that are too slow to do in Python, and (2) things that need to be available from stgit-helper in order to avoid Python's startup cost, such as top/applied/unapplied for the bash completion and bash prompt.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Re: [PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current'
Quoted 5 lines · Karl Hasselström
Quoted 3 lines · Karl Hasselström
We might consider having plumbing written in C or something, and make sure that the plumbing can be called directly if there's need, but it's going to complicate things greatly compared to pure Python.
Yes, it will complicate things. I think StGIT would have progressed at a much slower pace if written in C :-).
Quoted 5 lines
What I'm (foggily) envisioning here is to rewrite parts of StGIT (as little as possible) as a C library (libstgit.so?), and call the library both from the Python code, and from a "plumbing" C program (stgit-helper?). We should not try to make the library API stable, just like the current git library.
Apart from the start-up time, I don't see other major slowdowns caused by Python. It would be useful to use a git library directly without invoking external applications (I'm not sure what's the state of a "libgit.a" or what improvement we would get).
As for the start-up time, unless you write most of the commands in C, we would still have to load Python modules. If you run stg-prof instead of stg for a simple command like 'top', you can see that the main function takes about 60-70ms, the rest to 150ms reported by the external 'time' is Python start-up and module loading.
I had a quick try at using "freeze.py" to generate a binary (well, it includes python bytecodes but it might save time on module look-up) but it got confused by my optimisation to only load module commands based on the stg arguments. Maybe we should try this first.
Quoted 5 lines
There are two kinds of things we'd want to have in the library: (1) things that are too slow to do in Python, and (2) things that need to be available from stgit-helper in order to avoid Python's startup cost, such as top/applied/unapplied for the bash completion and bash prompt.
As you probably guessed, I'm not really in favour of re-writing parts of StGIT in C, at least not in the near future, though anyone can fork and re-implement it :-).
Signature · 1 line
Catalin
Re: [PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current'
Quoted 11 lines · Catalin Marinas
Quoted 6 lines · Karl Hasselström
Quoted 4 lines · Karl Hasselström
We might consider having plumbing written in C or something, and make sure that the plumbing can be called directly if there's need, but it's going to complicate things greatly compared to pure Python.
Yes, it will complicate things. I think StGIT would have progressed at a much slower pace if written in C :-).
I agree. C is not a good language to write a whole application in. But for the hot spots, C is a reasonable choice.
Quoted 8 lines
Quoted 5 lines
What I'm (foggily) envisioning here is to rewrite parts of StGIT (as little as possible) as a C library (libstgit.so?), and call the library both from the Python code, and from a "plumbing" C program (stgit-helper?). We should not try to make the library API stable, just like the current git library.
Apart from the start-up time, I don't see other major slowdowns caused by Python.
I haven't, either.
Quoted 3 lines
It would be useful to use a git library directly without invoking external applications (I'm not sure what's the state of a "libgit.a" or what improvement we would get).
There is no usable git library yet. But once there is, I agree we should use it.
Quoted 5 lines
As for the start-up time, unless you write most of the commands in C, we would still have to load Python modules. If you run stg-prof instead of stg for a simple command like 'top', you can see that the main function takes about 60-70ms, the rest to 150ms reported by the external 'time' is Python start-up and module loading.
My suggestion was to have a small stand-alone C program that could do some operations that need to be really fast, such as top/applied/unapplied. It need not have a nice user interface since it's only going to be called by scripts (bash-completion and the like), and it should only handle those operations that _must- avoid the Python startup penalty. And for sanity reasons, it should share code with stgit.
Quoted 4 lines
I had a quick try at using "
freeze.py" to generate a binary (well, it includes python bytecodes but it might save time on module look-up) but it got confused by my optimisation to only load module commands based on the stg arguments. Maybe we should try this first.
I agree that we should try pure-Python optimizations first.
Quoted 9 lines
Quoted 5 lines
There are two kinds of things we'd want to have in the library:
(1) things that are too slow to do in Python, and (2) things that need to be available from stgit-helper in order to avoid Python's startup cost, such as top/applied/unapplied for the bash completion and bash prompt.As you probably guessed, I'm not really in favour of re-writing parts of StGIT in C, at least not in the near future, though anyone can fork and re-implement it :-).
I wouldn't do it just for fun, either. But if it's a prerequisite to get good enough performance for something we really want, and all else has failed, I'd be willing to argue for the introduction of a C library and helper application.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Re: [PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current'
Quoted 7 lines · Karl Hasselström
My suggestion was to have a small stand-alone C program that could do some operations that need to be really fast, such as top/applied/unapplied. It need not have a nice user interface since it's only going to be called by scripts (bash-completion and the like), and it should only handle those operations that _must- avoid the Python startup penalty. And for sanity reasons, it should share code with stgit.
There is one more case to consider - people using NFS-mounted directories. The applied/unapplied commands would be even slower and the language overhead be negligible.
Another workaround would be to always generate the applied/unapplied files when the stack structure changes.
Signature · 1 line
Catalin
Re: [PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current'
Quoted 10 lines · Catalin Marinas
Quoted 7 lines · Karl Hasselström
My suggestion was to have a small stand-alone C program that could do some operations that need to be really fast, such as top/applied/unapplied. It need not have a nice user interface since it's only going to be called by scripts (bash-completion and the like), and it should only handle those operations that _must- avoid the Python startup penalty. And for sanity reasons, it should share code with stgit.
Quoted 6 lines
There is one more case to consider - people using NFS-mounted directories. The applied/unapplied commands would be even slower and the language overhead be negligible.
Another workaround would be to always generate the applied/unapplied files when the stack structure changes.
Yes, we could do that. These files would only be accurate when the stack was last modified with StGIT and not plain git, but that might be acceptable.
Hmm. Since the only way plain git modifies the stack is by changing HEAD (we assume the user doesn't manually mess with the patch refs), we might also write down the value of HEAD for which the applied/unapplied files are valid, so that the caller could call "stg applied" if the applied file was out of date. But that's quite a hassle to have to reimplement every time.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Re: [PATCH 1/2] Update the bash prompt from 'applied' instead of the obsolete 'current'
In reply to Catalin MarinasQuoted 3 lines · Catalin Marinas
BTW, any of you would like to get added as a member to gna.org/projects/stgit (there are no advantages, only e-mail updates for filed bug reports)?
You should not disregard the added bonus of being able to be assigned some of the bugs and tasks reported there :)
Best regards,
Signature · 1 line
Yann.
PATCH 2/2 Don't use / as separatar since it is common i branch names
In reply to Yann DirsonDon't use / as separatar since it is common i branch names
contrib/stgbashprompt.sh +2 -2
@@ -9,8 +9,8 @@ if [ "$PS1" ]; then ref=$(git-symbolic-ref HEAD 2> /dev/null) || return br=${ref#refs/heads/} top=$(tail -n 1 $git_dir/patches/$br/applied 2>/dev/null) \ - && top="/$top"; - echo "[$br$top]" + top=${top:-(none)} + echo "[$top@$br]" } PS1='\u@\h:$(__prompt_git)\W\$ ' fi
PATCH 2/2 Don't use / as separatar since it is common i branch names
In reply to Robin Rosenberg---
contrib/stgbashprompt.sh | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
contrib/stgbashprompt.sh +3 -3
@@ -8,9 +8,9 @@ if [ "$PS1" ]; then git_dir=$(git-rev-parse --git-dir 2> /dev/null) || return ref=$(git-symbolic-ref HEAD 2> /dev/null) || return br=${ref#refs/heads/} - top=$(tail -1 $git_dir/patches/$br/applied 2>/dev/null) \ - && top="/$top"; - echo "[$br$top]" + top=$(tail -1 $git_dir/patches/$br/applied 2>/dev/null) + top=${top:-(none)} + echo "[$top@$br]" } PS1='\u@\h:$(__prompt_git)\W\$ ' fi